[SUPPORT] Advanced Turn Based Tile Toolkit

Thank you - I’m going to do a bit more research. I’ll get back to you when I’ve made some progress!

Hey . I’ve built some unit spawners that direct units they spawn to a specific tile.

https://i.sli.mg/HuSRtP.jpg

They work flawlessly, when only one unit is being spawned and directed to move. However if I try to spawn more than one, and direct them to different tiles they break visually, and they end up just becoming stacked on top of each other in the same index visually due to not running the pathfinding per unit.

Having a hard limit of only moving one unit at a time isn’t a huge deal for this situation, since just spawning them on specific tiles and not moving them works perfectly, but it does make things like cinematics where I would want multiple units moving together not viable. Do you have any suggestions for how to get around this?

@: Looking forward to it! Good luck :slight_smile:

@Selentic: Ok, took me a bit, but I’ve got something to get you most of the way. The toolkit is built upon the notion that everything is truly turn based, and having multiple units act at the same time breaks this rule. I’m slowly trying to remove this limitation, but at the moment it takes a bit to work to achieve something like this.

The more specific reason for the problem you are seeing is that all units are referencing the same Path Index Array and spline in BP_GridManager and so they get stacked on top of each other. To fix this every unit need to have their own spline and path index array which is set up when they begin movement.

Unit_Parent already have their individual spline reference variables, just to cut down on casting and you can use this to set up a reference to a specific spline for this unit. For this I’ve created a new blueprint called BP_PathSpline that is a blank actor with a spline which I spawn at the start of unit movement and delete at the end of movement. There are probably more elegant ways to do this, but it is a quick and workable solution. Here is the part in the Event Graph of Unit Parent where I copy the spline held in BP_GridManager over to the new BP_PathSpline actor and also copies the Path Index Array from BP_GridManager over to a local array:

After this you will need to replace all references in Unit_Parent to Path Index Array from BP_GridManager with the Local Path Index array. You will also want to destroy BP_PathSpline at the end of movement. Also, I’ve been a bit silly and set it up so that units are removed from the Unit Array in ATBTT_PlayerController instead of in the Event Graph of Unit_Parent which would make more sense (I’ll change this in the next update), so you will also need to add this after Begin Movement in the event graph of Unit Parent:

I tried this out with the same nodes you posted a screencap of above and it seemed to work fine. There might be quite a few hidden problems since I haven’t had time to test it properly amid all the Christmas cheer, but if you meet any other tricky obstacles just let me know. As mentioned I want to take the toolkit in this direction in the future so I’ll be interested in hearing of any problems you might encounter.

Ah so that’s where the problem was. I was confused because each unit seemed to already have their own spline set during pathfinding.

Excellent, thank you. I’ve got a couple other things I have to finish up before I focus on this part again, but those should be done shortly. Once I’m done with those I’ll let you know how this works.

Oh man, it’s been a while since my unit_parent looked like that. I rewrote all that a while ago. That said, I spent more time than to admit when I started modifying things trying to find the part where it was writing the end position into the pawn array, though I thought it made more logical sense in the controller, but that might just be due to the context from the kind of game I’m working on. As long as they’re together though it should cut down on confusion for new people working with this.

Yeah, so was I. That was my original intention for adding the spline variable to Unit_Parent, but it seems like I only added a reference to the PathSpline in BP_GridManager. Looking into this now made me realise it did not work the way I intended (it is still somewhat helpful in reducing the amount of castingm though). I’ll think about how I’ll go about implementing separate unit splines in the future. There might be a more elegant way.

No problem. It should at the very least work for cinematic sequences.

I guess using either the Player Controller or the Pawn’s blueprint could make sense, but it should still probably be handled by one or the other and not a combination of both. Since the nodes for constantly updating the unit’s index during movement is natural to contain in the event graph of Unit_Parent I think it makes sense that the beginning and end of movement is also handled here. Especially since the player controller is set up to only control the current active unit, and one might want to move a different unit on one unit’s turn (possibly pushing it or commanding it to move). Containing it with the rest of the movement nodes in Unit_Parent is the best way to make sure that whenever a unit moves for whatever reason it is reflected in the Pawn Array.

Hi

I have been having a strange glitch lately where after adding in new events and functions to the toolkit, all of my unit’s attributes are reset to the default unit parent attributes. I have also been having a strange glitch where the game doesn’t order the pawns in initiative correctly. I added a initiative bar to my screen, that places an icon of each pawn on the screen in the order of the initiative array. Could that be causing the problem?

Has anyone else had this problem?

This is a widely reported bug with the engine (googling for it will find you about 8~ answerhub pages dating back to 2014 with no found solution) which I’ve been facing too. For no apparent reason the engine will reset children of blueprints at random to their default values. The issue also affects blueprints placed within your levels that have had attributes changed, where sometimes you’ll open it up and find that all custom data for every blueprint has been reset.

I’ve been dealing with this by simply zipping up a copy of my blueprints whenever I make significant changes to them so that when it occurs I can just reload those.

I got around to testing this out. The units no longer stack on top of each other, and end up in their appropriate spots, but all past the first just appear there without actually moving. I’ll look into this more tomorrow.

Thanks for the information Selentic. I’ll have to do that too. Glad to know it wasn’t me messing it up somehow. Hope they fix this error soon.

I have another question: Is there a function for changing the cost of a specific edge at run time?

As mentioned by Selentic this is a problem with the Engine and not the toolkit. It is pretty annoying to be sure, but nothing I can do anything about. I’m more uncertain about the problem with initiative order. Could you be a bit more specific about what sort of error you are seeing? How is the ordering incorrect?

It worked when I tried it out. I hope I didn’t forget something in my explanation. The error you are seeing seems to suggest that some part of the units’ event graphs are still referencing either the spline or path index array in the grid manager. Take a through look through unit_parent’s event graph.

Yep, there are a few functions listed under Utility in BP_GridManager. Set Edge Cost is probably the one you’re looking for, but there is also Remove Tile Edge, Make Tile Impassable, Remove Tile Edge Both Ways, Add Edge and Add Edge Both Ways.

It will allow the player to move two units, then switch over to move the entire enemy team, then allow the player to move the remainder of their team members. In the next round, everything is back to normal and all the players can move, then all the enemies, and so on and so forth.

Sounds like remove tile edge both ways is what I want. However it asks for index one and index two. I want to remove the east edge of the current tile and the west edge of the tile above it. Index 1 is the index of the current tile, correct? How do I find the index of the tile above the current tile?

Thank you for your patience and answers, by the way. :slight_smile:

Odd. And the only way you’ve affected the initiative order is by using it to inform the UI? But if you are just getting values from the initiative order array and not modifying it then nothing should change. What are the initiative values of the units? What do you see if you run a ForEach loop through the Initiative Order array at the start of the game?

If you are removing the edge both ways it does not really matter which is index one and which is index two. To get the index of an adjacent tile you take the tile’s index and either add or subtract a value depending on what tile you want. For a square grid this is as follows:

north: index - GridSizeX
east: index +1
south: index + GridSizeX
west: index -1

If you visualize it as a grid it should become obvious. Here is a 3*3 grid (meaning it has a GridSizeX of 3).

1 2 3
4 5 6
7 8 9

To get the index north of index five that would be 5 - 3 (GridSizeX) = 2. The east index would be 5 + 1 = 6 etc. Hex grids are a bit more complicated since it varies depending on if you are on an odd or even row. Are you using a hexagonal grid?

Happy to help!

Yes, all I do is grab from the initiative order to place widgets into my UI.

After running a for loop with appended object name to the initiative (index) number, this is what it prints out:

Unit _Player_Warrior is Initiative 8
Unit _Player_Skirmisher is Initiative 7
Unit _Player_AOE is Initiative 6
Unit _Enemy_Ranged is Initiative 5
Unit _Enemy_Ranged_2 is Initiative 4
Unit_Enemy_Melee is Initiative 3
Unit_Enemy_Melee_2 is Initiative 3
Unit _Player_Scout is Initiative 1
Unit _Player_mage is Initiative 0

Yes. It is hexagonal.

Ok, so it seems it is ordered that way from the start. What are the values of the initiative attributes of your units? If you want to have factions acting separately no unit of one faction should have initiative values overlapping the range of initiative values in the other faction.

Ok, that is no problem. I just remembered that I added functions for getting tiles in all directions in the last update. Check out the Get Adjacent Indexes function in BP_GridManager to see how it works.

You’re right! It was caused by my child blueprints resetting attributes. The enemy units were more noticeable because they changed from enemy to player units, etc. but the player units went unnoticed because for the most part, they behaved normally. Somehow I changed some of them back to one, but had missed others.

Okay so I tried getting index 1 (east) from the array to use its index in the remove adjacent walls function. But it doesn’t seem to be working. (I have tried both with and without the make tile passable functions, same result)

Here are some images:

grid.jpg

EDIT: I tried offsetting the location’s x value -100 instead of 100 so that it was actually the tile’s east side, and now it just blocks the tile in front instead…

The Mesh is set to ignore all collision channels, and the blue wall will be hidden in game and ignores all collision channels except RangeTrace.

EDIT2: I discovered that the edge costs were all set to 99… but they should have been set to 1 when I made tile passable…
I changed them to 1 and unplugged the make tile passable function, and now I can just walk right through the wall after setting the two adjacent edges…

EDIT3: I also tried adding the edge both ways with a cost of 99, but that didn’t seem to work either. Is it perhaps because it is done in the construction script?

Upon removing the 2D adventure game from the project (as I can look back on it with a fresh toolkit project and it simply takes up space in my project), it became clear that a few assets within are referenced in the base toolkit. The SM_Arrow_Flat mesh, referenced by the grid manager needs the M_Arrow material and Arrow texture from the 2D game. They should be moved to the toolkit so that the 2D game is indeed a true child of the game and therefore not needed. I already made the necessary changes for the project on my end by adding the needed texture and material to their respective folders and changing the material reference in SM_Arrow_Flat mesh, but just letting you know about it, in case you didn’t know.

Hmm, you’re seeing some strange behavior to be sure and I’ll look into it, but I’m a bit confused about what you are trying to achieve. Make tile passable is intended for tiles that are completely impassable to be made passable. It adds edges from that tile to all adjacent tiles. If what you want to do is to create a wall between two tiles you do not need to use this function, though. Just remove the edge between the tiles like so:

This creates an “invisible wall” between two tiles, but this is perhaps not what you’re after? If you could tell me more about your intended end result I can be of more help in suggesting how you go forward. I’ll be sure to look into the 99 cost stuff. Also, thanks for telling me about the 2D stuff referenced in the main toolkit. I’ll make sure to fix that in the coming update.

I have been migrating my project over from the 1.6 version of the toolkit to the 1.61 version and from UE 4.12 to UE 4.14 respectively. I’m having a new problem where now my enemy units will not even move. This started happening shortly after changing some things in the player controller and unit parent. But I have gone over the changes I have made and they should not have effected the functionality of the enemy units, because they were meant to only effect player units (which are working as expected). The other thing that could have effected them was another child blueprint reset to parent defaults. Unfortunately I had just made changes to the child blueprints so I couldn’t back them up (without having to redo the changes of course) so I simply setup the variables again. I did remove all the blueprints in the enemy units and removed the skeletal mesh (as my game uses sprites) and removed the Health Billboard because I use a Widget component for displaying health.

Do you have any ideas on what could cause the enemy units to not move? It switches to them, the camera hovers over them, then it switches to the next pawn instantly.

Yes, I want a wall between two tiles. I was building a tile that can be changed to a custom mesh, sprite, to be destructible, or offset.

Here’s a look into the construction script:

Continued from the right:

For now, I’m fine with the current results, where the units can move to the tile in front of but not behind the offset tile. But maybe in the future we can figure out how to get it to work.

It can be any number of things, I’m afraid, but I’ll tell you how best to troubleshoot it. Use break points in the event graph of ATBTT_AI_Controller to see if the nodes are firing in the order you expect them too. Identify the point at which it diverges from the path it follows in a fresh ATBTT project and compare the two from this point and back in the logic chain. Pay particular attention to the values of the arrays containing potential targets, such as reachable pawns, choice array and so on. I’m guessing the AI either does not register what enemy units are in range or discards the ones it has found. When you have found out more specifically where things break down I’ll be in more of a position to help you.

Ok, so to be clear your problem is that the wall above the center wall in your screenshot is not walkable and you want it to be connected to all surrounding tiles except the one below it?

So I’ve been comparing and adding breakpoints and the only difference seems to be that the new toolkit will initialize movement, and my project’s AI controller will not. The Choice array branch never hits true and Select unit and find path event never fires. It all comes down to the Choice array’s length never being above 0… therefore the branch that leads to movement never happens. Inside the Make choice function, the faction branch is always true, and never false. The enemy unit’s faction is set to “Enemy,” and the player unit factions are set to “player.” I checked if the pawn array was returning pawns and it is.

EDIT 1: So I changed the value in the find node from -1 to 0 and now the game is functioning properly (but possibly not allied factions?)

EDIT 2: When I look in the map Player is included as an allied faction for the enemies (added as an ally in the construction script). If I add a third faction, player is also included as an allied faction. The only change I made to the construction script was to take out the health bar.

EDIT 3: I simply deleted the player as an allied faction in the enemy unit and returned the value for find allied faction back to -1 and the game works again. It seems that when it reset the child units attributes, it kept the player as an allied faction, even when dragging in new child units into the map. Such a strange glitch! Thanks for your help in pointing me where to look. :slight_smile:

I want it to act exactly like your thin hex wall west or thin hex wall east, but be created in the construction script or at run-time. If it is on an even tile it is a hex wall and on an odd(offset) tile it is either a west thin wall or east thin wall.