[SUPPORT] Advanced Turn Based Tile Toolkit

Guide to updating to 4.8 (WIP):

BP_GridManager:

Set Marker Location (function): Delete the bottom “select” node and create a new one. Connect the output from Index To Vector On Grid to the bottom vector input. Split the top input and connect the three floats (X, Y and Z + offset) to the split vector. Set the index to boolean and connect “Use Index” to this bool. Connect the output of the “Select” node to the SetWorlLocationAndRotation function.

Create Spline Path (function): Remove the connection between ADD and Return Node.

Destroy And Clear Spline Path (function): Remove the connection between Destroy Component and Return Node.

Display Path As Spline (function): Remove the connection between Set Start and End and Return Node.

Compile BP_GridManager and follow the Yellow exclamation marks to the four Cast To Static Mesh Component issues. In each case, remove the cast and connect the previous input to the cast to the previous outputs from the cast. Connect up the execution pins on either side of the cast.

ATBTT_AI_Controller:

Make Choice Array (function): Remove the connection between ADD and Return Node.

Unit_Parent:

End Movement and Update Arrays (red comment box): Connect “Self” to the last “Set Array Element” node. (Edit: it seems this is not enough as the self nodes are disconnected each time the project is saved. This can be mended by casting self through Unit_Parent, though this is an awkard workaround).

Recieve Damage (purple comment box): Connect “Self” to the last REMOVE node. Get Index and connect it to the last Set Array Element Node. Remove the input from “Item” in the same Set Array Element Node.

Tile Parent:

Compile the blueprint and remove the unnecessary cast.

Other stuff:

Decals no longer seem to accept materials without textures plugged into their opacity. To fix all the Decal_Square decals, make a pure, white square texture and plug it into the opacity of each material.

There still seems to be a problem with switching pawns by clicking on them, that removes the current pawn from initiative altogether in some cases. I’ll look into it soon.

There might be other stuff as well. Please post in this thread if you encounter anything. And again I recommend sticking with 4.7 until 4.8 is out of preview if you want to ensure that there are no bugs.

They showed up when I tried it out yesterday, at least. Try changing the Default Tile Object in BP_GridManager to Static Mesh and see if it still doesn’t show up. If it does not there is probably something else that is wrong.

Thanks! Don’t know the reason for the migration stuff. I’ll add removing the cast in Tile_Parent to the list. I’ve found a couple of new problems too. Some of the changes seem to be reverted once the project is saved. The references to self in Unit_Parent are unplugged each time. You can get around this by casting self to Unit_Parent, but this should be unnecessary and gives a warning. It does work as a workaround for now, though.

They are seemingly automatically unplugged every time I close Unreal Engine. Is this not happening in your toolkit?

Another quick question:
How can I allow characters of the same faction to walk and see through each other without being able to walk and see through the enemy faction?

Something that might be worth looking into is adding the ability to place/reshape squares along a spline. (Thing a 1cm wide ribbon that gets sliced edge to edge every 1cm.) By allowing this, your project could be extended to basic board games and allow fast design and iteration of the board.

Yeah, I’ll report it to Epic so that it will hopefully be fixed before the finished update. I think that ends the work I’ll do on 4.8 for now, though. I’ll try to make my next large feature update coincide with the full 4.8 update.

Achieving this effect is possible, but you need to modify a few things. The main modification has to be done in the “Search And Add Tile” Function. This is a function within the Pathfinding function that designates tiles as walkable or not. Inside this functions all tile indexes that are added to Can Move to Array are set as reachable, while all indexes added to Open List Children are added to the next part of the search step, meaning it is potentially possible to move through these tiles. Here’s how it looks unmodified:

As you can see, empty, player, and enemy tiles can all be reached, but only empty tiles can be moved to. By hooking up tiles occupied by players to the branch, these tiles can also be moved through. However, this means that both players and enemies can move through player pawns and not enemy pawns. This is obviously not what you want to achieve. To make what tiles are added depending on the faction of the current pawn you could do something like this (sorry that it’s a bit messy):

Now this works almost perfectly, but there is one serious issue. If you want to attack an enemy in melee, by clicking on it so that you automatically walk up to it and hit it, and there is a friendly pawn right in front of it, the pawn will walk into the tile occupied by the firendly pawn. To prevent this, we have to make sure adjacent tiles to tiles occupied by friendly pawns do not hold enemies before we add them to Open List Children. To fix this we have to add another check and see if the parent tile (the one we are leaving) holds a friendly pawn. The graph begins to get a bit messy at this point, but I hope you can read it. I have to keep it tighly packed to get it all in one screenshot:

The basic idea is to get the index from the parent index (the one we are leaving), which is the second from the top of the four integer lines on the bottom, and check the Pawn Array to see if it is empty. We only want to mark enemies as reachable if the preceding tile does not hold a friendly pawn.

Ok, so we’re nearly there, but one issue remains. If the current pawn is standing next to a friendly pawn it is not allowed to move through it, because of the rules we just specified. Because of this we have to remove the current pawn from the pawn array before we start the search and add it again when we’re finished. Like this pretty early in the Pathfinding Function:

And this at the end of the pathfinding function:

Ok, I think that should do the trick. There might be unforseen consequences since I haven’t tested it for more than a few minutes. I’m planning to implement a more elegant version of this when I make the Dungeon Crawler example map.

Edit: I forgot to mention. If you are using a square grid where all or some troops are not allowed to cross corners you have to also add the same changes to the function “Search and Add Tile Diagonal Cross Corners False”.

Hi RAVaught, I’m afraid I don’t completely understand what you mean. Are you talking about building levels in the viewport or at runtime? Could you mention some games that would be possible with this solution that would not with the toolkit in its current state? Perhaps you could draw a very quick mockup in paint, as I’m struggling to visualize your suggestion.

Hey !
Quick question: On event X I want to spawn decals (like the movement range (blue) or attack range (red) ones) on specified tiles. For example to indicate tiles where special actions are possible. Also there are actors (snapped onto the grid) on all the tiles that should be highlighted with a decal.

To accomplish this I tried using the “Spawn Decal at Location” node. I specified a decal Material, got the DecalSizeSquare (Grid Manager) and put that into Decal Size Input. Life Span is set to 0 for infinite, Rotation is 90, 90, 0.

For the Location Input I got the locations of all actors on the tiles that should be highlighted (Get Actor Location), then I got their indices (Function: ‘Vector To Index Interface’, Grid Manager) and with them the same indices of the ‘Vector Field Array’ (Grid Manager). I then added the Vector Field Array entry of the specific Index to the Actor Location (sum of vectors) and used this as the Location Input of the “Spawn Decal at Location” node.

Unfortunately no decals are spawned. I checked with breakpoints if the blueprint gets to the “Spawn Decal at Location” node and that’s the case. It just somehow seems to get skipped… Any help would be appreciated :smiley:

Edit: Also is there a way to show such a tile decal on all tiles that overlap with a collision box? For example to create an ability that increases movement cost of all tiles in a sphere collision radius?

Glad to see you’re getting creative with the toolkit, Hinato! Seems like you’ve got a pretty good grasp of things, and as far as I can se there’s just one mistake that prevented you from achieving your desired result. You do not need to add the location of your actors to the location you get from the VectorFieldArray, as you’re essentially adding the location twice, placing the decal twice as far away from 0,0,0 as you want. Delete the “plus” node and connect the Get output directly to Spawn Decal and it should work. The reason you would want to add something to the output of the Get is if your GridManager is placed at a location different from 0,0,0 in which case you have to add the location of the Grid Manager.

However, I cannot help but feel you’re overcomplicating things a bit here. If you have already placed actors snapped to the grid where you want the decals to be, why don’t you simply get the location of those actors and spawn the decals at those locations directly? I see no need to use the Vector To Index Interface or Vector Field Array in this case, unless I’ve missed something.

Thanks a lot! Found another small bug which could have been the problem but at least now I can see the decals…
I started out with just using the location of the actor but since I the decals weren’t shown in the right spot I tried using the Vector to Index Interface. Right now there are still some problems with the exact location but I’m going to fix that right now :smiley:

Ok, good luck! I’ll be here if you need any more assistance.

Hi ,

How can I make a Cone Trace that can be used for cover system and also for an overwatch system?
I just want to trigger my overwatch event if a unit enters into a pawn view field, like in XCOM Enemy Unknown.

I saw that UE4 doesn’t have a Cone Trace, but somebody created a similar task by using Sphere Trace:

As for Cover System, I’ve fulfilled an array with all walls position and their “cover” attribute (it’s a new attribute, of course).
So, after every unit movement, I know if my unit has a wall coverage on his northern, southern, eastern or western closest square.

But now I have to increment victim defense if it is under cover. So basically I need to fire a cone trace from the attacker to understand if the attack comes from south, east, north or west, and apply the eventual coverage.
Do you or somebody have any idea to achieve this?

Hi Wisdom-,

I’ve given this some thought, as I plan to implement similar features in an upcoming example map. There are of course several ways to do what you ask, but here’s how I’d do it. Since you already have a cover array that knows the direction of the cover (pregenerated I assume, since that would be most efficient), finding whether the attacker is between an attacker and the target should be very easy. Just subtract the X and Y locations of the attacker from the targets X and Y location. If X is positive the attacker is to the east, if Y is negative the attacker is to the north etc. No trace needed in this case.

For cone tracing I think that might also be more complicated than what you need. What I would do is to periodically do line traces to all enemy units currently on overwatch. Doing this on tick is probably overkill, but probably not that bad on performance, since there will probably not be a massive amount of units on overwatch in a given level. Either way I’d probably set it up to fire an event every time a unit enters a new tile. If any of the traces (using range trace) are not blocked (get hit result returns false), check the look at rotation between the unit on overwatch and the target. If it is a reasonably small number, trigger your overwatch event. The result should be pretty much identical to a cone trace, I think.

Hi ,
Great ideas, as usual :slight_smile:

Your solution is about firing an overwatch event, and that’s really great even if I will maybe reduce line trace check during tick event, creating an increasing index integer and firing the line trace only when index % 4 = 0 (or more than 4, if needed)
That’s should increase system overall performance, even if a line trace is not an expensive operation.

My actual concern, unlike XCom, is to create a mobile and rotating sight area selection when you select overwatch special ability (by displaying, for example, 2 red lines that simulate the unit view field), so that I am concerned about the altitude. That’s why I think I’ll need a cone trace, or maybe I need to create an invisible cone mesh. When I apply that view field, using your idea, I will just change the unit rotation and apply a boolean value (isInOverwatch) to true, then continue to check line trace on tick % 4 = 0.

But can line trace be useful when attacker and victim are at different altitudes?

My solution works equally well for different altitudes. Just check both pitch and yaw. If either is below a certain threshold, fire your overwatch event. Or use only yaw, since I don’t think you’d want players to specify the pitch of their units heads when putting them in overwatch. My solution does not allow you to display a visible cone, of course, even though the result will be similar to a cone. If you want to display the cone you could of course use a semi-transparent cone mesh with the same angles as you’ve set as the cutoff for checking yaw. This wouldn’t visually account for cover, though. In that case you’d probably want to shine some sort of conical light from your pawn.

A small update on some features I’m working on. Visibility can now also be displayed as a frame, just as for movement. More importantly, pawns can now figure out what is the optimal tile to move to for attacking a target. They can be set to prefer long or short ranges or whatever takes the least amount of movement. This is useful for AI, where ranged units might want to keep their distance, or enemies will want to move minimally in a game with shared action points between movement and attacking.

btaTBEn.jpg

Note: The new features work equally well for 3D games.

Hello ,
I bought your toolkit but i have some issues. Every time i try to add this asset to my project and i try to create the grid it crashes my unreal or when it not crashes, the blueprints loses some Events. What is the best way to import to my project? Sorry for the question i’m totally new to unreal, but i love the asset.
Thank You

Hey ,

Got a few questions -

  1. Does this work with the World Composition feature that comes with Unreal 4? I am currently building a large scale environment that I would like to turn into a Turn Based Strategy game Proof of Concept. If you are unsure I can send you over my environment so that you can test it out.
  2. Do you plan on adding a Asynchronous Turn Based Game Mode to your Turn Based ToolKit? Basically both players take their turns at the same time, then they lock in their moves and then the game plays out or simulates the turn.
  3. Does this support more than one player on the same computer?

I know that this sounds dumb but I am basically making an “Mixed reality Wargame” Similar of that of Supreme Commander or Total Annihilation for the CastAR and Microsoft Hololens when they come out. In the mean time I am laying the ground work for the game.

Thank you for your time,

HeadClot

Hi Pitchohavers, I’m sorry that you’re having issues. The toolkit was originally designed so that almost all functionality was contained within BP_GridManager, so that the toolkit could be easily added to other projects just by placing the grid manager in the level.

I later split up the functionality over multiple blueprints, which has a lot of benefits, but does make it harder to add the toolkit to a preexisting project. I have asked Epic to change the text in the launcher to say “Create New Project” instead of “Add to Project”, but it seems they haven’t gotten around to it yet.

In any case the “Add to Project” button does the same thing as “Create New Project” at the moment. Therefore I would recommend you to create a new project with the toolkit and import all your custom meshes/blueprints etc. to that project instead of the other way around. If you for some reason need to do it the other way, you might run into various problems depending on how your old project is set up. At the very least you will have to import the config files as well as the content files. This is not done when using migrate, so you will have to copy the config files between the project folders directly.

So to repeat, you should create a new project if this is not a big hassle. If it is, you also need to include the config files. If you do this, do you still run into the same problems? Could you specify what events are lost from what blueprints?

Hi HeadClot,

since you are making a game that is a bit outside of what the toolkit is intended for, you will need to do more work yourself, but believe what you are asking should be possible, depending on your implementation.

  1. As per the most recent update, the toolkit can generate a grid on top of anything that has collision set to block PathTrace. This should also work with world composition.
  2. I have no plans on adding asynchronous gameplay to the toolkit at the moment. It should be possible to do this, but it would certainly take some work.
  3. Not out of the box, but this should be relatively easy to add. The biggest change would be needing to to change the toolkit to support more than two factions.

I think I solved all compatability issues when I wrote the Conversion guide two pages ago, though I might of course have missed something, and there have been two new minor 4.8 updates in the meantime. The plan is to have the next large general update of the Toolkit released at the same time as the full 4.8 release. I’ve reposted the conversion guide below. Is there anything that is missing, or that has been rendered unnecessary because of the minor updates to 4.8?