Hi, I’m pretty new to UE4 but I have been having an issue where I cannot spawn mesh cubes into the game. What I’ve done is create a blueprint based off of a c++ class and in the blueprint editor I gave it a cube mesh. The code I use to spawn the blocks is the following,
In my constructor:
static ConstructorHelpers::FObjectFinder<UBlueprint> ItemBlueprint(TEXT("Blueprint'/Game/TopDownCPP/Blueprints/TerrainBlock.TerrainBlock'"));
if (ItemBlueprint.Object)
{
TerrainBlockBlueprint = (UClass*)ItemBlueprint.Object->GeneratedClass;
}
and then in my actual method:
void Main::Generate()
{
UWorld* World = GetWorld();
FVector fVector;
FRotator fRotator = FRotator(0, 0, 0);
if (World)
{
fVector = FVector(20, 100, 0);
World->SpawnActor<AATerrainBlock>(TerrainBlockBlueprint, fVector, fRotator);
}
}
Just to test this out I called the Generate method from the GameMode constructor and I set a keybind to it and called the Generate method from the PlayerController. Neither worked unfortunately.