Download

[SUPPORT] Advanced Turn Based Tile Toolkit

Haven’t had much time to play with your toolkit yet. Mid Summers Eve and all. But I’ve been playing around and looking through your blueprints. I’ll make sure to give you an update with my progress! :slight_smile: Might take some time since it’s rather big, but this’ll get me started just fine!

While I’m here, when I make a grid (hex) too big (let’s say 320x208) I get an error: Infinite Loop Detected in BP_Grind_Manager, asset during ForLoop with the following Call Stack:

Script call stack:
Function /Game/AdvancedTurnBasedTileToolkit/Blueprints/Gameplay/ATBTT_GameMode.ATBTT_GameMode_C:ReceiveBeginPlay
Function /Game/AdvancedTurnBasedTileToolkit/Blueprints/Gameplay/ATBTT_GameMode.ATBTT_GameMode_C:ExecuteUbergraph_ATBTT_GameMode
Function /Game/AdvancedTurnBasedTileToolkit/Blueprints/Gameplay/BP_Grid_Manager.BP_Grid_Manager_C:Activate Grid Manager
Function /Game/AdvancedTurnBasedTileToolkit/Blueprints/Gameplay/BP_Grid_Manager.BP_Grid_Manager_C:ExecuteUbergraph_BP_Grid_Manager
Function /Game/AdvancedTurnBasedTileToolkit/Blueprints/Gameplay/BP_Grid_Manager.BP_Grid_Manager_C:Add Viewport Terrain To Arrays
Function /Game/AdvancedTurnBasedTileToolkit/Blueprints/Gameplay/BP_Grid_Manager.BP_Grid_Manager_C:Create walls on grid edges

d018297477ce747b760da1cab8f956413ac32947.png

As well as the same error message for Reverse for each loop:

897c597f2e985b2ae08ab8a1d4eade2a26d2f24c.png

Next time I tried (reloaded the entire project) I got 320x208 to work with “LogScriptCore:Warning: Script Msg: Attempted to access index ###(different number) from array VectorFieldArray of length 66560!”.

Can you just explain the errors a bit?

@Askyl: The error you’re seeing is because you are hitting the loop limit, roughly meaning you’re going above the maximum set limit of calculations to do during a tick. This makes UE4 assume that there is an infinite loop in progress which crashes the program instead of letting it freeze forever.

The reason for this in your case is that ATBTT does a lot of precalculation at begin play to reduce the need for heavy calculation during gameplay. How much is done depends on how you have set up the grid manager. If you have heightmaps enabled, for instance, a line trace is sent downwards on each tile location to determine their height. For multi-level grids several such traces are used, if you enable trace for walls one such trace is used between all neightboring tiles etc. Since you have a 320x208 grid that means that each such calculation is done 89600 times(!).

There are ways to get around this limit, but I’m curious why you need to have such an absolutely massive map. Even the “huge” map in CIV VI has a map size of only 128*80 tiles, making it roughly one 9th of your map in size.

For the solutions, though, there are two things you can do. The first is simply to increase the loop limit in project settings. It can be found in Project Settings -> Engine -> General Settings -> Maximum Loop Iteration Count. Try adding another zero to this, and I think the error should disappear. However, for maps of this size I would recommend pregenerating the grid before the game starts, so that clients would not have to do these calculations once the game has been built. Pregenerate Gameplay Grids is a public boolean in the grid manager. This uses the construction script, which also has a much higher loop limit. If you do this, note that any changes you make to the map after checking this boolean will not affect the map, so make sure to re-check this boolean if you make any changes.

How does it affect performance if you have each skill spawned as a separate actor in a map? Like in the Jungle Raid example. Let’s assume there are around 30 pawns in a map, each pawn has around 20 skills (average) and 7 pieces of equipment. This raises a number of actors to around 1000. Maybe it’s better to have a number of bool variables and spawn/destroy specific skills when needed looking at those variables? I’m not a big specialist in coding so I can be completely wrong of course.

Yeah, I gave this quite a bit of thought when I first made the skill system. Unreal Engine has a really high threshold for invisible actors, so it is very unlikely to be an issue. Ian Shadden, who made a turn based strategy system in parallel with me used invisible actors to represent all tiles of his grid. From his reports this did not affect performance much and for a large grid this could reach 50000 actors or more. I prefer to refrain from using loads of invisible actors unless I have to and use arrays instead, but this is mostly personal preference.

This preference extends to the skill system, though, and initially I did as you suggest and spawned skill actors when needed. However, having individual actors had benefits like storing the number of remaining charges, cooldowns etc.

One of the things I’m currently working on for the next update is making the skill system a part of the base toolkit and as such I am trying to make it cleaner, simpler and more flexible. What I’m doing now is to have all units with the same skill share the same skill actor. When a unit with a skill system component is spawned, the map is checked for instances of its skills. If the skills do not exist in the map and instance is spawned. If not, a reference is set up tied to the already existing skill actor. This way there will never be more skill actors in a map than there are skills in play.

To solve the issue with charges and cooldowns units now have an optional skill sysytem component that tracks its skills and their cooldowns/charges etc.

But like I said this mostly comes down to taste. For the number of actors you are describing this should not really matter.

Might I suggest:

Right now pawns are placed on the grid in the editor ahead of game time, with their skills chosen from a public editor variable drop down list. Simple, static, and handy, right?

Soon as I got deeper into working on my game did I realize that these skills and player stats need to persist to the next battle, and the static placement and selection of stats doesn’t work for that, so characters needed to load from a data file.

Perhaps you might consider loading the characters/pawns and all their stats, placement locations, and skills from an start up struct file, and placing them dynamically on the grid at game (grid manager init) start.

Thoughts?

Thanks for the suggestion! For games that includes character advancement of persistent characters between levels, some sort of solution similar to what you have mentioned will need to be implemented. I would want to add something like that in addition to and not as a replacement to the current solution. ATBTT’s built-in drag and drop placement is very easy to work with and is suitable for many sorts of TBS games, so I’ll always want to keep that as the default. The Spawn Unit function is included to easily add units dynamically during gameplay, but it will always create a default unit of the class selected, so it is not sufficient for persistent units with changing abilities and attributes. The best solution for persistent units is something I believe is pretty genre dependent, so if I add this in the future I think I would want to do so in a game example. For my next game example I would like to make something similar to a tabletop rpg like D&D, and for this I’d want to add some sort of database solution for tracking character advancement. I won’t be adding this in the next update, but somewhere further down the line.

Few more ideas for ya:

So I had to add a Boolean on Spawn Unit() of Grid Manager, as right now it adds unit to the initiative by default. Adding the boolean allows you to avoid adding it by default.

Spawn Unit.png

Also, I added a “Load All Player Units” function call to Grid Manager, and call it from Game Manager right before the “Sort Pawns In Initiative Order()”. The “Load all Players()” loads characters or creates based on a save slot, and Spawn Unit()s each unit.

load characters.png

Init Character.png

Init Character () is a helper class I made to make setting all variables much much easier. It also sets up the unit references at the start.

game mode.png

And now, my game board has no player units places in the editor; they are all loaded dynamically. The Sort Pawn In Initiative Order() call right after Load All Player Units() then adds all the editor Pawns AND the dynamically created one to the Initiative order at this time. If the character had data in the save slot to load, than all the inputs are mapped to the Init Character() instead of the defaults or manually set variables (not shown in photo).

The next goal is to kinda figure out a better way to place them. By Index could work I figured out, but I need a helper class of some sort to figure out what index a particular square is IN EDITOR.

You got any ideas for that? Setting by location kinda works, that is just super lame as I have to create an object in editor to drag around and then copy the coordinates that way. Maybe there is a way to create an editor object that displays Index is possible?

Bonus question!

How are you saving Arrays of Arrays? Array of Pawns with an Array of Skills. If you are implementing multiplayer you are using gamestate I assume and that you require the use of that right? My guess is moving to an set of Boolean values for knowing a skill or not. Any other ideas?

Thanks for answering my questions earlier, just bought the toolkit. I’m trying to play around with using the grid in a map that is already compiled and I’m using the Simple Office demo level for this. I’m using a grid that is larger than the intended playing area and was planning on walling off the outside of the map with the invisible wall pieces. I’m finding that the pawns can’t move when inside the level even though I don’t have the invisible walls setup yet.

Is there a way to get the grid to ignore the collision of anything that isn’t the intended invisible wall pieces or am I just doing something completely wrong collision wise here? Also I do believe collision is active for all of the meshes in place but turning them off seems to change nothing.

How do I get the pawns to move inside the level?

@Curiosichi: Thanks for your suggestions and showing me your own solution :slight_smile:

Spawning the units early on before Sort Units in Initiative makes sense. Your functions for adding the units seems a bit cumbersome, however. If you have to specify all attributes and the location of each unit manually I don’t really see the benefit compared to placing the actors directly in the viewport. At the very least I would create a sub-function that you could loop through using a custom struct array containing all relevant variables. That way it would extend to any number of units. Other than that it is hard to provide input when I’m uncertain of the goal you wish to achieve.

If I did something like XCOM, for instance, I would probably store each character in a custom struct array in the game instance, or possibly use a data table. The attributes would in this case be created by a combination of base stats, random variation and player input. If you tell me your goal I can provide better suggestions for a good way of solving it.

As for figuring out which index a particular square is, you can check Precalculate Gameplay Grids and then check Show Tile Indexes. Note that if you make any changes to the map that would affect pathfinding after this point you need to re-check Precalculate Gameplay Grids.

As for arrays of arrays, the easiest way is to make a custom struct that contains an array and then make an array of these structs.

@OperatorCrux: To be honest I have no idea what is going on here… When the path is displayed pathfinding seems to work fine for the tiles inside the walls, so the grid setup is not affected. I think the only explanation is that the trace under the mouse pointer is being blocked somehow, but you say that removing collision from all the other meshes did not work, so that is odd. I would try one more time to be sure. Check through the scene outliner and make sure that collision is disabled for all meshes and volumes in the scene. You don’t really need to disable all collision, just the one for PathTrace, but as a quick test just disable collision for them. Come ask me again if you’re positive all collision is disabled (except for the Grid Manager, of course) and I’ll think hard to find out what might be causing this.

Cumbersome in this use case, but it isn’t actually ever used.

My game creates all the character data before we get into game mode / grid manager, so when loading player units, it loads from the save file. In the picture I linked above, that is the false side of a branch checking for that save data. And in early development, I just load a few characters as if they were placed on the grid.

d23effcd6a6ef168dcc310ed00791197ca0cf1eb.png

So since I have to save each stat individually, I iterate over the arrays of the save file data and create the characters. Granted yes, the stats will likely be generated by the items the character has equipped, this is more just a proof of concept.

I create Starter Tile objects that are placed in the grid manager, and use their locations to map starting locations for the loaded character units. I select, from the top of the saved character list, one by one to place on those tiles. For example, if I have 2 starting grid locations, I pull the top two character’s save data and load them onto the map on those two tiles. In the same way, If I had N starting tiles, I select first N characters to place on those tiles. A simple Is Valid() check on the retrieved character data array avoids any problems trying to fill a character start tile with an invalid character.

Do note, that Skills are still not saving since I have not remedied the array of arrays issue, but i’ll look more into the structs. Or maybe i’ll do a list of Boolean values for “know skill” for each skill in the game, and if they know the skill add it to their list of skills here.

My desired result:

game start
Save character data if it doesn’t exist
Load desired battle map / game manager
Load character data/skills/items
place units on grid
do the battle
Battle end
Save experience gains / new items acquired for all player units
repeat

I also need to keep in mind if I make/want multiplayer (which I will probably wait for your implementation) I will have to change both the save data with game state. I haven’t researched it much yet.

@Curiosichi: Ok, that seems a lot more reasonable. I’d really recommend you to look into structs, though. Not only can you easily make nested arrays, but you can also simplify your above function substantially by using an array of structs containing all unit attributes instead of having a separate attribute for each one. The game state is kind of like an extension of the game mode for variables that need to be replicated, such as a list of players etc. Useful in multiplayer, to be sure, but I don’t think it is warranted for the spawning of units at the start of the game.

Alright so I solved the problem! I had disabled collision for everything except the ceiling. So it turns out that the ceiling tiles were having some weird collision error because the collision box went lower than the mesh itself. Disabled the ceiling collision and it works perfectly now.

Ok, good. That was the only possible cause I could think of, so I’m glad taking a second pass did the trick.

Hey, this is the thing I’m thinking about now. Before you spawn the skill actor you need to know if your pawn has learned it or not. Obviously you can’t do that based only on “learned” boolean or something like that in skill class. The most crude but the simplest way is to create a few booleans (one for each skill) in pawn class and this is fine enough if you have relatively small number of skills. But if you have (let’s take Final Fantasy Tactics as an example) over a hundred of those skills? And if all booleans will be in the same function it will literally look like Tower of Babel. I’m sure there are more elegant ways but I’m still looking for them.

Well my thinking is if not Boolean, the current setup has each pawn spawning an actor and holding a reference, so whether its a Boolean or a skill reference, one way or anther there is going to be a huge list of skills. Unless I can think of a bit flag and corresponding map on a single variable, but I haven’t had to think in binary and how that might work in Unreal yet.

Don’t think it gets any smaller then a bit flag, but its still the same principle, maybe just less memory though.

I’d probably go for a Set of skill class references. I highly doubt this would become a memory issue. There would have to be an extremely large number of skills per unit + stored units for that to be the case.

How are multi tile units coming :)?

Haven’t made any more progress on that progress specifically. As mentioned I’ve planned to split the next update into two so I can get it out faster. First I’ll finish the update with everything but multi-tile units (networked multiplayer, major refactoring, transform-independent grids), as adding multi-tile units before this would just complicate making these changes later. I’m making great progress at that front, though, so in that sense I’m getting closer :slight_smile: The next update is mostly feature-complete at this point, but there is still a long process remaining of testing, bug-fixing, structuring, commenting etc. Summer holidays is also going to slow down my progress the next few weeks, but I’m putting a lot of my free time towards getting it done in a timely fashion.

Neato. Really looking forward to it.

Hey,

Currently attempting to get the units to spawn dynamically, however the pack doesn’t seem to like that as I get dozens of accessed none errors if there are no units on the grid when it starts(most likely the custom unit spawns is getting called after the other begin plays already initiated), however there never is a certainty of which items will spawn as it’s generated from another level(how and why is not relevant).

Are there events I need to delay until after I spawned the units myself? If so, could you point me to which ones I need to callback after spawning the units? PC/Pawn/GM/Etc? I can callback all of them but to avoid breaking anything I find it safer to just ask.

Currently just calling back the gamemode and it seems to work.