UE4 c++ OnComponentOverlap and OnComponentHit syntax
Vložit
- čas přidán 22. 08. 2024
- Quick set-up of a basic actor in c++, including the on component overlap event.
Overlap declaration:
UFUNCTION()
void MyOverlapFunction(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
Hit Declaration:
UFUNCTION()
void MyHitFunction(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
How to bind overlap:
MyPrimitiveComponent(Point)OnComponentBeginOverlap.AddDynamic(this, &AMyActor::MyFunction);
How to bind hit:
MyPrimitiveComponent(Point)OnComponentHit.AddDynamic(this, &AMyActor::MyFunction);
Note using (Point) as it won't allow greater than or less than signs in description.
thanks for the tutorial! I really like how you explain little things like where to quickly find the right signature; definitely would appreciate more ue4 c++ tutorials from you
+ReaverPS Thanks! I'll do more if I think of any topics to do them on
your computer sounds like a hoover
If you are doing this in a later UE4 don't forget to include #include "Components/SphereComponent.h"
In a later UE4 I don't even have AddDynmaic anymore, just Add and AddUnique 😢
Thanks so much for the help!
Is your computer running Crysis in the background? All jokes aside - great video man! Extremely helpful and to the point!
ARIGATOU SENPAI!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ^-^ SUGOI!!!!!!!!!!!!!! ONII CHAN SAMA~~~~~~~~~~~~~~~
handy video so ta. fan noise is a bit nuts haha
+ResoImages Bah I know, sorry for that. Glad you found the video helpful though.
Can you link to the .cpp and the .h file in the description please?
Have you had any issues with OnComponentEndOverlap? I can't seem to get it working despite the fact that it should be correct.
I think a little while ago they changed the actual parameters so if you're copying my syntax it won't compile. If you go to about 5 minutes into the video, I explain how to go to the class the event dispatchers are declared in, and copy the up to date signature, that will always work.
Thanks for the quick response. I got beginoverlap working with the new signature and endoverlap should be working with the new signature, but it's not.
Function:
UFUNCTION()
void OnOverlapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
Binding:
BoxCollision->OnComponentEndOverlap.AddDynamic(this, &ADisplacementTankSlot::OnOverlapEnd);
I know this comment is over six years old but incase anyone is having trouble with this. During UE 5.3 the signature is
void OnDelegateExampleOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)