Call function of an actor from a different actor

That will work. You can simply the ‘if’ statement to something like:

#include "ASpecificClass.h"

if ( otherActor->IsA(ASpecificClass::StaticClass()) )

Hello all! First post. Just started learning UE4 and am having a great time. :slight_smile:

I’ve been messing around with a lot of “proof of concept” type projects i.e. things that have potential to be expanded into something useful when I decided to design my first game.

Anyway. The thing I’ve been trying to get down right now is cross-class communication. (In hopes of solidifying my ability to create a full-fledged damage system)

I managed to do the following, but I’m wondering if there is a solution that is a bit more elegant.

//I would like to cast the object to the specific class only if it is in fact the correct type. 
if(otherActor->getClass()->getName() == "ASpecificClass_C") {

	ASpecificClass* obj = Cast<ASpecificClass*>(otherActor);
	obj->recieveDamage(25);

}

Full-disclosure… I am writing this at work, so the syntax may be slightly incorrect, but you get the idea.

Any help is greatly appreciated!

P.S. Any general advice on how to approach learning UE4 is great! the other two things I want to look at soon are a basic multiplayer system, and sphere traces (for AoE). If anyone has any references, I’d be ecstatic. :smiley:

Thank you! This is a much cleaner solution.