Call a function in another class?

Just an example
So lets say i have this in class A cpp:

void UClassA::BeginPlay()
	Super::BeginPlay();

void UClassA::FuncTest()
{
	UE_LOG(LogTemp, Warning, TEXT("Test"))
}

but now I want to access it in another class, classB cpp:

void UClassB::BeginPlay()
{
	Super::BeginPlay();
    FuncTest(); //Call it here

I’ve read some examples but I don’t quite fully understand them, so far I think you have to do something like:

UClassA* Message = Cast<UClassA>(what goes here???); 
Message->FuncTest();

I know you have to include the header file of ClassA in the ClassB file, but what else do you have to do?

UClassA* Message = Cast(what goes here???);

here goes the pointer to an object that can be casted to a type of UClassA.

Now you need to somehow obtain that pointer. I don’t know the relationship between these two classes so I can’t assume how UClassB should get a pointer to an object of type UClassA, it’s for you to decide.

1 Like

Thanks that solved my problem, i was able to get the pointer :slight_smile: