SpawnActor() not accepting my parameters

Hi, I am trying to spawn a BP in code and am having trouble working out what the SpawnActor() function is not accepting my parameters.

I think it probably has something to do with my not having done c++ since school and there is some obvious syntax i am doing wrong but i cant for the life of me work it out.

My BP is defined in the header as follows:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = BPClasses)
		UClass* MazeTileBP;

And then i am trying to spawn my grid with the following code:

void AMazeGameMode::GenerateMaze(float tileX, float tileY)
	FActorSpawnParameters SpawnInfo;
	SpawnInfo.bNoCollisionFail = true;
	SpawnInfo.Owner = this;
	SpawnInfo.bDeferConstruction = false;

	if (GEngine)
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("GENERATING MAZE"));

	for (int x = 0; x < tileX; x++)
		for (int y = 0; y < tileY; y++)
			FVector TileSpawnLoc(x + tileX, y + tileY, 0.0f);
			FRotator TileSpawnRotation(0.0f, 0.0f, 0.0f);

			AStaticMeshActor* NewTile =	GetWorld()->SpawnActor(MazeTileBP, TileSpawnLoc, TileSpawnRotation, SpawnInfo);

The line where i am calling GetWorld()->SpawnActor() at the end is telling me there is no such overload that accepts the params i have given it but they seem like correct params to me.

Any help spotting what i can’t is appreciated!



Thanks for the reply staticvoidlol, i have it spawning my tiles now :slight_smile:

Is that what is called a template class or something?

I think i need to do some reading on those!


I’m not entirely sure of the technical details, but I think this just instructs the Spawn function to return an actor of type <AActorClass>.

It is a ‘templated function’, and staticvoidlol is correct that it determines the return type of the function, so you don’t need to do a cast. The ‘untemplated’ version of SpawnActor returns an AActor*, so you would need to cast it to an AStaticMeshActor*.