Hello,
I am fairly new to Unreal Engine c++ programming and I am doing this to get started with something.
I am trying to generate a tiled grid that will act like a game board similar to what you see in turn based Tactical RPG’s like FF Tactics.
I have a “Tile” blueprint that inherits from StaticMeshActor which in turn inherits from AActor base class. What I am trying to do is generate the grid using this tile blueprint, instantiating them from code and storing them into a 2D array with their own properties.
Should I be using a custom c++ actor class to do this or is spawning the actor blueprint fine?
For some reason the code I am using to spawn the tile actor is not working for me.
I am doing the following:
GameMode.h
UClass* tileBP;
GameMode.cpp - Constructor
static ConstructorHelpers::FObjectFinder<UBlueprint> tileBrueprint(TEXT("Blueprint'/Game/Tile'"));
if (tileBrueprint.Object) {
tileBP = (UClass*)tileBrueprint.Object->GeneratedClass;
}
And then to instantiate the tile I am using this template I found made by Rama:
template <typename VictoryObjType>
static FORCEINLINE VictoryObjType* SpawnBP(
UWorld* TheWorld,
UClass* TheBP,
const FVector& Loc,
const FRotator& Rot,
const bool bNoCollisionFail = true,
AActor* Owner = NULL,
APawn* Instigator = NULL
) {
if(!TheWorld) return NULL;
if(!TheBP) return NULL;
FActorSpawnParameters SpawnInfo;
SpawnInfo.bNoCollisionFail = bNoCollisionFail;
SpawnInfo.Owner = Owner;
SpawnInfo.Instigator = Instigator;
SpawnInfo.bDeferConstruction = false;
return TheWorld->SpawnActor<VictoryObjType>(TheBP, Loc, Rot, SpawnInfo);
}
and im calling it like this:
GameMode.cpp
void ATacticsRPGGameMode::BeginPlay()
{
Super::BeginPlay();
FVector SpawnLoc = FVector(0, 0, 0);
FRotator SpawnRot = FRotator(0, 0, 0);
AActor* NewActor = SpawnBP<AActor>(GetWorld(), tileBP, SpawnLoc, SpawnRot);
}
I would be very thankful if someone could point me out where my mistake is, and what I should be aiming to do.
Thanks in advance.