Hi all,
I’ve been following this tutorial, updating the outdated parts as I go along and deleting the parts I don’t think I need. This is a simplified version of my header file:
#pragma once
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class MYPROJECT4_API AMyActor : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(VisibleDefaultsOnly, Category = Projectile)
USphereComponent* CollisionComponent;
UFUNCTION()
void OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
public:
AMyActor();
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
float RunningTime;
virtual void NotifyHit(UPrimitiveComponent* MyComp, AActor* Other, UPrimitiveComponent* OtherComp, bool BSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit) override;
};
and a simplified version of my cpp
#include "MyProject4.h"
#include "MyActor.h"
AMyActor::AMyActor(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
PrimaryActorTick.bCanEverTick = true;
CollisionComponent = ObjectInitializer.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComp"));
CollisionComponent->InitSphereRadius(50.f);
OnActorBeginOverlap.AddDynamic(this, &AMyActor::OnOverlap);
OnActorEndOverlap.AddDynamic(this, &AMyActor::OnEndOverlap);
RootComponent = CollisionComponent;
}
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//Define new atom position
FVector NewLocation = GetActorLocation();
SetActorLocation(GetActorLocation() + MyVelocity * DeltaTime, true);
}
void AMyActor::OnOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor != this)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, ("Do the thing"));
}
void AMyActor::OnEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0, FColor::Green, ("Ok, don't do the thing"));
}
void AMyActor::NotifyHit(UPrimitiveComponent* MyComp, AActor* Other, UPrimitiveComponent* OtherComp, bool bSelfMoved, FVector HitLocation, FVector HitNormal, FVector NormalImpulse, const FHitResult& Hit)
{
Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);
FVector ReflectedVelocity = (-2 * FVector::DotProduct(MyVelocity, HitNormal) * HitNormal + MyVelocity);
MyVelocity = ReflectedVelocity;
ReflectedVelocity.Normalize();
}
This keeps giving me the following pesky error for OnOverlap and OnEndOverlap
Error C2664 'void TBaseDynamicMulticastDelegate<FWeakObjectPtr,void,AActor *>::__Internal_AddDynamic<AMyActor>(UserClass *,void (__cdecl AMyActor::* )(AActor *),FName)': cannot convert argument 2 from 'void (__cdecl AMyActor::* )(AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &)' to 'void (__cdecl AMyActor::* )(AActor *)' MyProject4
(if you find other errors, this is a result of my hasty editing job to try and make my code shorter for this post). Does anyone know where I’m going wrong?
Thanks in advance!
Craig