Hi all,
I have a character class which uses a custom AI controller class. I have created a BP using my character class which adds a skeletal mesh actor to it. When I just drag and drop the BP into the editor and play my game the custom AI controller works fine. However when I spawn the BP from code the AI controller is NULL. I am not sure why is this happening.
In the constructor for my character class I define my AIController class
AIControllerClass = AStrategyAIController::StaticClass();
I am also doing some testing in the PostInitializeComponents function for my Character class
if(!Controller)
{
UHelperFunctions::drawDebugText("[AStrategyChar] Controller NULL before post!");
}
Super::PostInitializeComponents();
if(!Controller)
{
UHelperFunctions::drawDebugText("[AStrategyChar] Controller NULL after post!");
}
UHelperFunctions::drawDebugText("Post Initializing");
The second print doesn’t happen for BPs spawned by dragging and dropping in the editor. However when spawned from C++ code both the prints happen.
I spawn my characters using the following code
spawnedActor = GetWorld()->SpawnActor(ElephantBP, loc + FVector(0,0,522), FRotator(0,0,0));
spawnedActor->SetActorRelativeScale3D(FVector(6,6,6));
I am not sure why this is happening. Any clues ?
Many thanks.
Cheers,
Shailen