So I’ve searched and searched… maybe I’m just passing the answer over and over again. I’m just trying to catch when the character hits a wall, that’s it.
I’ve done this in blueprints, but trying to get it over to c++ is just not working, so I was hoping someone could explain how I can get the hit result when running into a wall in c++.
I have the source, but surely this can be done in a c++ project without having to go into the actor class? I feel dumb asking such a simple question, but at this point I’m just wasting my time by not asking.
Capsule, Character, whatever, just want to catch collision. I just want to be able to run into a wall and output a debug message saying its hitting the wall.
There are two ways of detecting collision for an actor. Either you use the built in Hit function or you bind a function to a UPrimitiveComponent’s OnComponentHit multicast delegate.
and implement your logic there. Don’t forget to call Super::NotifyHit!
Approach #2:
Say you have a reference to a specific primitive component that supports collision like a static mesh or a capsule collider. You can add a custom UFUNCTION to its OnComponentHit delegate like this:
Don’t forget to remove your function from the delegate for example in EndPlay by calling RemoveDynamic instead of AddDynamic. It uses the same signature.
Sorry for the weird layout but the code sample block is not that useful in terms of easy to read layout.
How would I put this in the character class though? It only throws errors, as it should because it’s actor.
Using the first option (in the .h):
Error C:\Users****\Documents\Unreal Projects\SoD3D\Source\SoD3D\SoD3DCharacter.cpp(337) : error C3867: ‘AActor::NotifyHit’: non-standard syntax; use ‘&’ to create a pointer to member
Then putting this in the character.cpp (throwing the error, line 337 is the super:: part):
Just to note for anyone else wondering the same dumb things I do, the answer to the question seems to be no, you cannot do this in the character.cpp class. You have to extend off the Actor class, or something to that effect with the correct lingo included.