In attempting to create a C++ RTS game (loosely based on the brilliant 3ProngGaming’s blueprint only one on YouTube) and I’ve gotten completely stuck on it.
I’ve created two new classes. A ConstructionManager class and a Ghost Interactible Master Class with Blueprints for both and the 1x1 cube static mesh chosen.
In the header file:
// Construction Manager to Spawn at Begin Play
UPROPERTY(EditDefaultsOnly, Category = "Set Up")
TSubclassOf<class AConstructionManager> ConstructionManagerClass;
// Ghost building to Spawn at Begin Play
UPROPERTY(EditAnywhere, Category = "Set Up")
TSubclassOf<class AGhostInteractiblesMaster> GhostClass;
UFUNCTION(BlueprintCallable)
void SpawnConstruction();
UFUNCTION(BluePrintCallable)
void SpawnGhost();
And in the cpp file:
void AMyGameStateBase::SpawnConstruction()
{
if (ConstructionManagerClass)
{
FVector Location(-400.f, -500.f, 235.f);
FRotator Rotation(0.f, 0.f, 0.f);
FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
()->SpawnActor<AConstructionManager>(ConstructionManagerClass, Location, Rotation, SpawnInfo);
UE_LOG(LogTemp, Warning, TEXT("Construction Manager Class Spawned at %s"), *Location.ToString());
}
}
void AMyGameStateBase::SpawnGhost()
{
if (GhostClass)
{
FVector Location(-400.f, 110.f, 235.f);
FRotator Rotation(0.f, 0.f, 0.f);
FActorSpawnParameters SpawnInfo;
SpawnInfo.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
()->SpawnActor<AGhostInteractiblesMaster>(GhostClass, Location, Rotation, SpawnInfo);
UE_LOG(LogTemp, Warning, TEXT("Ghost Class Spawned at %s"), *Location.ToString());
}
}
In my Blueprint, I have the following:
The problem is that while the Ghost class spawns fine, the Construction Manager does not.
The UE Log shows the following:
LogBlueprintUserMessages: [ThirdPersonExampleMap_C_9] Spawning Character
LogBlueprintUserMessages: [ThirdPersonExampleMap_C_9] Spawning Construciton
LogSpawn: Warning: SpawnActor failed because no class was specified
LogTemp: Warning: Construction Manager Class Spawned at X=-400.000 Y=-500.000 Z=235.000
LogBlueprintUserMessages: [ThirdPersonExampleMap_C_9] Spawning Ghost
LogTemp: Warning: Ghost Class Spawned at X=-400.000 Y=110.000 Z=235.000
So the code to create the actor is being called with the correct class actually being specified in blueprint but for some reason, I’m getting a “SpawnActor failed because no class was specified” error message despite the fact that both pieces of code, apart from their names, are 100% identical.
Is there something I’m missing?