So I have a component attached to multiple actors. Some which are AIs. I want to separate some functionality using a simple if statement. Now I know I could separate this using subclasses but that will not do what I want. I specifically want this “dirty” way of doing it (just debugging).
From the component I can get the owner like so:
AActor *b = Cast<AActor>(this->GetOwner());
But trying to get the first player controller actor crashes the editor.
Even if that would not crash I cannot find how to properly compare two Actors to make sure it is in fact the correct one (in this case the possesed default player). Searching for answers I find some information but only in Blueprint and looking at the C++ API I cannot find the same functions.
GetCharacter() returns an ACharacter object, and because ACharacter is a child class of AActor, the result is already the actor you want to retrieve. So there’s no need to call GetParentActor() on that, and this call will probably return NULL.