How to use/read api doc ? / c++

Hello guys ,

I try to create a function on c++ who depends of Hits events , so i found this on the api’s doc :

“Called when this actor is involved in a blocking collision.” well nice , but how to use it in code ?

I’ve already make the function in BP , but i really want to create it only in c++

Thanks a lot , and have a pretty nice day :wink:

In order to do this in C++ you would simply use the Add Code to Project wizard to add a new class to your project that is based on Actor (or some other class which is derived from Actor as well.)

Inside the source for that class you can override the OnActorHit event to add your own functionality. I’d recommend calling Super::OnActorHit first so the engine can carry out it’s normal processes before you perform your own logic.

I tried them both , but it still doesn’t works :’(

Hi,

please checkout PathFollowingComponent.cpp line 800. There is an example on how to bind a native function to OnActorHit.

FScriptDelegate Delegate;
Delegate.SetFunctionName(TEXT("OnActorBump"));
Delegate.SetObject(this);
MyPawn->OnActorHit.AddUnique(Delegate);

Hope this helps,
Eckhard

How do you mean? Can you post a code example? Is the code being executed, and are you making sure to actually use the new C++ class instead of your blueprint?

OnActorHit is a struct , but i tryed to have a function like this :

void OnActorHit()
{
   //do something ...
}

but i don’t really know how to do that , i come from unity3D , on it you have a OncollisionEnter() function which is call every frame when your actor is colliding something .

But here we have a struct which is call so i don’t really know how to transform this event into a function calling . Or maybe i should use an other method

Hello i forget to send the answer , so after looking in the fps exemple project , i found how to do it :

// I call my function Oncollision()

in the .h add this :

UFUNCTION()
    	void OnCollision(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

then in the .cpp

YOURCOMPONENT->OnComponentBeginOverlap.AddDynamic(this, &AArrow::OnCollision);

void AArrow::OnCollision(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
	{
		// do some stuff
	}
}