Download

Spawn actor not working

Does anyone know why my spawn actor isn’t working, I’ve been trying to get it working for hours now.
This is in the game mode class.
header -


UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FloorTiles")
TSubclassOf<ATile> TileToSpawn; 

cpp -


FActorSpawnParameters SpawnParams
GetWorld()->SpawnActor<ATile>(TileToSpawn, FVector(0.0f, 0.0f, 0.0f), FRotator(0.0f, 0.0f, 0.0f), SpawnParams);

Can you be a little more specific? What exactly is going on? Error? Spawned but doesn’t appear? Not in the world?

Basically it returns a nullptr even when I have made sure that I have chose the sub class correctly, however just now I have tried the exact same code in my player class and it works so I’m not sure why this doesn’t work in my game mode class.

Just to be sure, even if you set *TileToSpawn *in the game mode, check if it has a valid reference. Other than that, I don’t understand why it fails in the GM and not in the player.



if (IsValid(TileToSpawn))
{
   FActorSpawnParameters SpawnParams;
   SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
   auto act = GetWorld()->SpawnActor<ATile>(TileToSpawn, FVector(0.0f, 0.0f, 0.0f), FRotator(0.0f, 0.0f, 0.0f), SpawnParams);
   UE_LOG(LogTemp, Warning, TEXT("ACTOR SPAWNED"));
}
else
{
   UE_LOG(LogTemp, Error, TEXT("INVALID REF"));
}