x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Generating tile grid

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.

Product Version: UE 4.10
Tags:
more ▼

asked Mar 26 '16 at 06:36 PM in C++ Programming

avatar image

limpit666
1 1 4 6

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question