[SOLVED] Cast PROBLEM

Problem: Fail to cast actor, created with c++

Created actors Actor1 and Actor2. Created variable in Actor2 to, assign Actor1 via Blueprint. Now I need to cast that Actor1 blueprint in C++.

Fail to cast, like this: AActor1 TempActor = Cast<AActor1>Actor1Var;

Sorry, for noobish question.*

Your syntax is wrong. Unreal’s cast is a normal function call so you need the () .

You can do:


AActor1* TempActor = Cast<AActor1>(Actor1Var);

Then use an if statement to check if the cast was successful:


if (TempActor != nullptr) { //Success! }

Thanks for reply. Still it is failing to cast.

Solved, partly. Cast variable type was TSubclassof<AActor1>, changed to AActor1*.

You can’t cast a TSubclassOf variable directly to a pointer of the type. It’s a pointer to a class, not an instance.