SpawnActor failed because no class was specified 4.22

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:

285911-classsetup.jpg

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?

Where do you call SpawnConstruction and SpawnGhost?

Currently, they’ve been made BlueprintCallable so are being called from the level blueprint when I press the F key but I will have them being called directly from the C++ BeginPlay when I can get it working.

Your workflow seems correct. Have you tried deleting your binaries & intermediate and rebuild the project?

Edit: On ()->SpawnActor(GhostClass, Location, Rotation, SpawnInfo);
Try switching GhostClass to GhostClass->StaticClass()

I’ve now tried deleting the folders and rebuilding, no change.

Interestingly, I moved everything to my Game State C++ files and without changing a line of code, it works perfectly but where I want (or at least the BP tutorial says to put) everything, the CameraPawn files, it doesn’t.