sarram
(Cube)
1
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.*
Balgy
(Balgy)
2
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! }
sarram
(Cube)
3
Thanks for reply. Still it is failing to cast.
sarram
(Cube)
4
Solved, partly. Cast variable type was TSubclassof<AActor1>, changed to AActor1*.
Jambax
(Jambax)
5
You can’t cast a TSubclassOf variable directly to a pointer of the type. It’s a pointer to a class, not an instance.