Hi,
First I want to say that I’m completely new to the community and I want to thank you for the good documentation and all the good questions in the forums and I hope some day I’ll be able to answer to questions too … but until then…
So I started with the 2D Slider sample and I want to practice some of the new things I learned by making it something like Super Mario. I changed the animations, made the map but now I have a problem with the bricks that when are hit give coins.
I found that event : On Component Hit | Unreal Engine Documentation is probably the event I’m looking for but I didn’t find any documentation for it for the C++ version, like how to use it and etc.
Yeah, Blueprints are fine but I’d really like to learn UE with C++.
Can someone help me, how should I bind a function to that event? And is there something,like some boolean, I should enable before that so the event fires?
Ok after googling with the right words I found this:
For the OnHit event you should use in the header:
UFUNCTION(BlueprintNativeEvent, Category = Collision)
void OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
Then you bind the event to your Collusion component (in our case the sprite):
sprite->OnComponentHit.AddDynamic(this, &ACoinBrick::OnHit);
And finally you implement the OnHit:
void ACoinBrick::OnHit_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit){
//oops I'm hit
}
Note: If you dont use UFUNCTION’s BlueprintNativeEvent you have to drop “_Implementation” from void ACoinBrick::OnHit_Implementation.
The main problem here was how to find which event has returns which parameters. I can’t find the documentation for these like for this one it returns (AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) but I was lucky I found it in the forums. Isn’t there any documentation?