I posted this question on both reddit and the answerhub, so I feel a bit bad for spamming but I’d really like to find an answer since I’ve run out of things to try.
I’m testing on two objects that both use the UFO static mesh from the flight starter template. On both Static Meshes I’ve set the Generate Overlap Events, set CollisionPresets to OverlapAll, and set Simulation Generates Hit Events.
In my constructor I have:
static ConstructorHelpers::FObjectFinder P2MeshClass(TEXT("StaticMesh'/Game/Flying/Meshes/UFO.UFO'"));
PlaneMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PlaneMesh0"));
PlaneMesh->SetStaticMesh(P2MeshClass.Object);
Planemesh->OnComponentBeginOverlap.AddDynamic(this, &ASpaceGamePawn::OverlapBegin)
I also have:
and
And later on, here is OverlapBegin
void ASpaceGamePawn::OverlapBegin(class AActor* Other, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& Hit)
{
//Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);
GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Blue, TEXT("YAAARRRR"));
// Pass to Dynamics Component
UActorComponent* OtherSDCActorComp = Other->FindComponentByClass(USpaceDynamicsComponent::StaticClass());
USpaceDynamicsComponent* OtherSDC = Cast<USpaceDynamicsComponent>(OtherSDCActorComp);
if (!OtherSDC)
return;
SDC->NotifyHit(OtherSDC, Hit.ImpactPoint, Hit.ImpactNormal);
}
NotifyHit does work when the two things are set to BlockAll, and NotifyActorBeginOverlap works when they’re set to overlap all, but why don’t the components work?
Unfortunately NotifyActorBeginOverlap doesn’t work for me since it doesn’t have the HitLocation and HitNormal vectors or an FHitResult.
MPalacios
(MPalacios)
March 21, 2016, 9:08pm
2
Do you make sure to attach the Planemesh to whichever actor owns it? That way the collision settings you set to ‘this’ is passed on to Planemesh.
It gets attached to the RootComponent of the actor.
queelaga
(queelaga)
March 22, 2016, 7:03pm
4
Make sure your functions “ActorOverlapBegin” and “OnHit” are marked as UFUNCTIONS(), otherwise dynamic binding won’t work.
2 Likes
I was indeed missing the UFUNCTION() on the functions, but it still doesn’t work after adding them.
Here is my header snippet:
public:
ASpaceGamePawn();
// Begin AActor overrides
virtual void Tick(float DeltaSeconds) override;
UFUNCTION()
virtual void OnOverlapBegin(class AActor* Other, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& Hit);
// End AActor overrides
Here are my source snippets:
// Create static mesh component
static ConstructorHelpers::FObjectFinder<UStaticMesh> P2MeshClass(TEXT("StaticMesh'/Game/Flying/Meshes/UFO.UFO'"));
PlaneMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PlaneMesh0"));
PlaneMesh->SetStaticMesh(P2MeshClass.Object);
PlaneMesh->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Overlap);
PlaneMesh->OnComponentBeginOverlap.AddDynamic(this, &ASpaceGamePawn::OnOverlapBegin);
RootComponent = PlaneMesh;
void ASpaceGamePawn::OnOverlapBegin(class AActor* Other, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& Hit)
{
//Super::NotifyHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse, Hit);
GEngine->AddOnScreenDebugMessage(-1, 50.f, FColor::Blue, TEXT(“YAAARRRR”));
// Pass to Dynamics Component
UActorComponent* OtherSDCActorComp = Other->FindComponentByClass(USpaceDynamicsComponent::StaticClass());
USpaceDynamicsComponent* OtherSDC = Cast<USpaceDynamicsComponent>(OtherSDCActorComp);
if (!OtherSDC)
return;
SDC->NotifyHit(OtherSDC, Hit.ImpactPoint, Hit.ImpactNormal);
}
Does any variable or function not declared inside the overlap begin function also have to be made a UFUNCTION or UPROPERTY?
queelaga
(queelaga)
March 24, 2016, 10:30am
6
Try moving your binding (AddDynamic) from the constructor to BeginPlay().
That did it! Thank you much!
Voclost
(Voclost)
March 23, 2018, 11:53pm
8
Thx mate that helped me too
Cheers
Thanks Man! Really Helpful!! It stuck me for days!