Hi all, so I’m trying to spawn a random actor from my uclass array but I’ve been struggling to get it to work and the spawnactor just keeps returning null or crashing depending on what I try.
So this is my array:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "FloorTiles")
TArray<UClass*> TypesOfTiles;
Then this function gets a random actor:
UClass* AEndlessRunnerGameModeBase::GetRandomTile()
{
int RandomNum = UFunctions::RandomValue(0, TypesOfTiles.Num() - 1);
UClass* RandomTile = TypesOfTiles[RandomNum];
return RandomTile;
}
And this is the function that spawns the actor:
void AEndlessRunnerGameModeBase::SpawnTiles()
{
RandomTileClass = GetRandomTile();
if (RandomTileClass)
{
FActorSpawnParameters SpawnParams;
ATile* NewTile = nullptr;
NewTile = GetWorld()->SpawnActor<ATile>(RandomTileClass->GetClass(), PreviousAttachPointLoc, PreviousAttachPointRot, SpawnParams);
}
}
Any help is much appreciated, thank you