[SUPPORT] Advanced Turn Based Tile Toolkit

Ok, so here is what I’m guessing is happening (without being able to check my code). When your attack animations are being called in my offensive abilities an immediate QueueAction macro is called, which culminates in an attack animation being played by the unit. Before the action is queued I bind an event to an event dispatcher which is responsible for showing damage dealt and ending the action. As part of this it also unbinds the event from the dispatcher.

Since the event is unbound as soon as it is called only the first attack will call the dispatcher. However, if you do not unbind it, EndAction will be called twice (which would result in issues, since you have not queued two actions. This would then end whatever the next action in the queue is). You could fix this by splitting it up. Have one event that is bound to one dispatcher, which is responsible for displaying damage dealt and another responsible for ending the action. The first dispatcher should be called whenever an attack animation lands an attack (through notifies), while the other should be called first when all attack animations have ended. Only this second event should unbind events (both) and end the action.

This is the sort of question that I wished I was back home for, as it would help to do some testing, but I’ll try my best.

So, there are roughly as many corners on a square grid as there are tiles (since all tiles have four corners, but most corners are shared between four tiles). As you mention you can put an object at the corner of a tile by placing it on the center of a tile and then offsetting it by half the width of a tile on both the X and Y axes. This is in fact what I do with multi-tile (“big”) units that occupy an even number of tiles along both axes. In the case of units sized 2*2 tiles, for instance, the unit “really” occupies only the top left of the tiles (as far as its GridIndex variable is concerned). You should be able to do something similar with your corner objects.

But this leads to some complications, as you have noted. Your objects cannot be units, or units will not be able to stand on the tile which is occupies on the grid. You should thus not use units for this. Luckily I’ve included another TMap called GridObjects which was made with these sorts of things in mind. By using AddObjectToGrid you can add a reference to your objects to any tile without disrupting unit movement. Check out the items in the HydrasLair map for examples of how to add and interact with GridObjects.

For the aura effects of your objects, that increase damage, reduce health etc. on adjacent units you can get all the appropriate tiles pretty easily. If the object really occupies the top left tile you can get the object’s GridIndex as well as GridIndex + 1, +1000 and +1001.

So to perhaps the trickiest part, which is targeting the objects with an attack. If you use a special type of attack for just targeting these objects but not units it is relatively straightforward. You would just offset the hover marker similarly to what I do for the move ability when you have a 2*2 unit as the active unit. Again you are really targeting the tile to the top left of whatever tile you are hovering over here, but for all gameplay purposes it works as if you are targeting the space between tiles.

However, I am guessing you want your attack abilities to be able to attack both units and your objects depending on what the player is hovering over, which again leads to the problem of units and your objects occupying the same tile. It was for these sorts of corner cases (forgive the pun) I made it so that abilities store not just the index of the tile being hovered over (or clicked), but also the precise world location under the mouse. You likely want to make a child actor of BP_AbilityBase that you use for your abilities (at least the ones that can target the corner objects) where you override some of what is done for the hover and click events. Normally I here check if the mouse is hovering over something that blocks path trace, which is a valid tile etc. Before this you could do a line trace for your corner objects (using some trace channel your objects are set to block. Do not use PathTrace or RangeTrace for this, as this will affect visibility and pathfinding). If this channel is blocked by one of your corner objects, do not run the regular hover and click events, but instead make custom ones which target the custom corner objects.

This is the general approach I would take for implementing something like this. It takes a bit of work, as you can see, since you’re violating an assumption of the toolkit, which is that anything relevant to gameplay exists withing tiles. However I have kept these sorts of things in mind while designing the toolkit, which makes such modifications much simpler than they could have been. I hope this helps you. I can go into more detail once I’m back from my vacation early next month if you are still in need of help.

This is a lot simpler. Modifying health or damage is as simple as modifying any variable in UE4 (though for health you would also have to remember to update the health bar appropriately). The only bit of modification you would need to do here would be related to how you determine the killer whenever a unit is killed. There are several ways you could do this. You could do this by adding a reference to the source unit in the TakeDamage event in BP_Unit and run your LevelUp event for this unit if CurrentHealth of the target is 0 after taking damage. If units only ever take damage on other unit’s turns you can simply check what is the current ActiveUnit in BP_TurnManager whenever a unit dies and level up this unit. You could even level up as part of your attack abilities. After dealing damage with the attack, check if the target unit still lives (several possibilities here. Is health 0? Can the unit still be found in the initiative array? Has a custom bDead boolean been set to true), and level up the OwningUnit if this is the case.

Thanks for your detailed feedback :slight_smile:

I’m going to give all of your suggestions my best shot and hopefully won’t need too much guidance along the way.

I can’t figure out how to do this. :confused: Is there any way to revert the toolkit back to the version before the action system? I’ve always been bad with figuring out where and when and how to use events.

Hi. I’m making a turn by turn game that is more in the line of a chess or checker type game. That is, the pieces move one or two squares at a time, capture a piece by either moving into the opponet’s piece square or jumping it, depending on the situation. The pieces themselves are spaceships and bases.

Any tips on using your product to build a game like this?

Also, I’ve seen your tutorial vids, (great work on them and the product by the way), but since I can’t always watch vids, I was hoping that there was some kind of pdf type of documentation. Something I can download and refer to without using a vid. (I know it’s old fashioned :slight_smile: ).

thank you for your product and your attention.

Hi ,

Just finished up watching your Ability video and wanted to see if I’m understanding correctly that you intended to make a video of how to set up a new ability from scratch, but it hasn’t come out yet (if it does exist, would love to see it). Thanks

With regards to the question I had about setting up pieces on the corners of squares, and your answer about how there are nearly as many corners as squares, I’m wondering what you think about the feasibility of building another 7x7 grid on top of my 8x8 grid (by setting the position correctly we can make the center of every tile on the 7x7 grid rest on top of the corners of all of the tiles on the 8x8 grid). I know the toolkit wasn’t designed to be used with multiple grids, but if we built communication between them, would that be a potentially easier way to go about it?

Secondly, I have another piece of functionality that I am trying to build in to abilities. I’m trying to make it so that players have a number of Action Points (AP) for their whole faction, as opposed to for each owning unit. In other words, the owning units AP cost is being subtracted from a limited share of total AP that belongs to the whole faction (moving a unit costs 1 per square, attacking costs 2 per target, some other abilities may cost 3), and this number is determined at the beginning of each faction’s turn by a random integer in range 1-6.

Within this functionality, I also need a way for units to attack single targets together. Something like select multiple units and doing a single attack with them on a target. For some context, my game is designed to incentivize players to have their units work together to attack single targets by having an attack on a single target always cost 2 AP, no matter how many units you’re using, whereas if you’re attacking separate targets it costs 2 AP per attack.

Thanks so much and looking forward to getting a sense of how difficult this might be and how you would go about it. All the best.

Sorry for the delay. Been out biking the last couple of days. Will get to your questions now.

Sorry to hear you are struggling. As soon as I’m back home in a weeks time I’ll be able to give you a more detailed explanation (with screenshots). It is possible to get a version without the action system, though I cannot really recommend it. It is so different from the current version and a couple of years old at this point, so it would be very difficult for me to provide support. To get it you have to select version 4.14 in the dropdown when creating a new project with the toolkit. If you choose to convert in place to use a newer version of UE4 with the older ATBTT you likely have to fix several issues to get things working properly.

I can give you a hacky solution for your problem for now, which is more in line with how I would have done things in older versions. Keep the event dispatcher for the events that show damage on the health bar, but disconnect it from the EndAction event. After binding the dispatcher create a delay node. Have the delay be long enough that all your attack animations are completed (you could get a custom float variable from the OwningUnit for this so you can vary it for units with different animations. Once the delay is over, unbind the dispatcher and call EndAction.

Hey, I recently answered a similar question about chess movement in this thread. See if this answers your questions and let me know if you have any remaining questions: https://forums.unrealengine.com/unreal-engine/marketplace/31005-support-advanced-turn-based-tile-toolkit?p=1653018#post1653018

As for the PDF question, yeah I can see how that would be useful to people. The main reason I have not done so is that it is quite time consuming, and my dev time is already quite limited. There are still a lot of tutorial videos I need to do, so it would be a long time until I feel I can afford the time. Sorry about that. I hope you can still make use of the video tutorials and let me know here if you need me to clear something up.

Yes, that is indeed high on my list. I am planning this as my next video after I’ve made a video on pathfinding.

Hmm, can be done, but you’re breaking some built-in assumptions which means you’ll need to do some extra work. As far as pathfinding is concerned, the toolkit does not really care about the layout of the grid. You can set GridLocations to be anything you want and connect tiles for pathfinding with GridEdges in an arbitrary fashion. However, the code for finding grid indexes based on a location and finding tiles in range both make assumptions about the grid structure. You would thus have to make custom methods for finding tiles in range, for instance. Selecting corner tiles would also need to be done in a different fashion to the regular conversion from location to grid index. All of this is doable, but tricky. I think my suggestion for using GridObjects and faking the offset would be a much simpler solution to your problem.

This should be pretty straightforward to implement. In any code that gets or sets the AP of a single unit instead get or set the AP of your group AP. This value could perhaps be stored in the TurnManager or GameState. I assume you already know how to get a random integer, which is what you would do at the start of the turn.

This one is a bit more difficult, though also doable. I’d probably want to make a new custom ability for this (based on BP_AbilityBase, probably, as it is quite nonstandard) that handles selecting multiple units at once and getting them all to attack. This is another of those questions I wish I was home in order to answer better. Essentially you would keep an array in the ability of selected units, where you can add new units by clicking them. Then when clicking an enemy you would loop through all the units and have all of them attack the target unit (in the game logic). Then you would queue an action with this array of units and the target unit as inputs and in AnimateAction loop over these units to play their attack animations.

Happy to help, and hope my answers are useful. You’re trying some stuff that requires somewhat large modifications to the toolkit. Nothing that is impossible by any means, but I hope you’re prepared to spend a lot of time learning and experimenting. Best of luck, and let me know if you have any follow-up questions.

Hey ! I was wondering if there’s an easy way to merge changes from your recent updates into my slightly older version? Would be a shame to have to go file by file and see what I have changed. I would love to get the updates! Also, is the animations while moving still in the Experimental folder? Or is it part of the standard stuff now? Thanks!

Hello ,

I ran into a problem with the Game Over message never showing up in a certain circumstance. After a week of debugging and listening to you videos over and over, I figured out how to solve it and will explain it now.

So I have a unit with 3 Action Points and 3 Abilities something like this:

Move
Staff Attack (melee)
Lightning Strike (ranged)

I always had everything in code working fine, except in one situation. That is when the AI used the Melee Staff Attack to kill the last enemy in game. That leaves 1 or maybe even 2 Action Points left with that unit, so the Turn never ends, the game freezes in the RunNextAction loop, and the game never displays Game Over Message never shows up even though the game is over and the unit just runs idle animation.

Anyhow, after a week of debugging, this is where I found to set the AI Unit’s Action Points to zero when the game was over and the Unit still had Action Points left.

It’s in BP_Unit - Select Actor

Add the code with yellow edges.

So basically, the code sets the current AI Unit’s CurrentAP to Zero when game is over so next Turn starts and Game Over will be displayed even if AI Unit has Action Points left.

That code doesn’t hurt anything , I would add it next update.

Would have saved me a week of frustration.

It really took a week to figure out where to put that code. A very painful week.

Unfortunately diffing and merging is limited with blueprints. I think Perforce has some functionality for this, but I have not tested it myself. I try to mark most changes in a new version with a comment named after the new version.

You can search for these comments in blueprints to find most of the changes. However, I do not mark every minor change I make in such a fashion, so it is not perfect. It is possible to make updating to a new version simpler by not touching any of the core blueprints of the toolkit, but adding your changes to child actors of these blueprints. However, this can sometimes limit you in the sort of changes you can make, so it is unfortunately not ideal either.

The safest approach, and the one I would generally recommend, is to merge and copy over your own custom changes manually. However, this is of course time consuming, so you’ll have to consider whether the changes in the update are worth the hassle, or if it is better to keep working with the older version. I wish I had a better answer for this, but I’m afraid I’m not aware of any perfect solution for this.

I’m very sorry to hear that you had to bang your head against the wall for a week for this, Locoweed. This is something that I should clearly have discovered and fixed a long time ago, and I thank you for posting your solutions here. From your screenshots it seems like you are not using the latest version, though. My last update was a major overhaul of the turn system, which I had hoped would eliminate these sorts of issues (among other things). I am away now and cannot confirm for myself for another week, but I will certainly look into this when I’m back and see if this is still a problem. If so I will make sure to fix it.

Are the animations while moving still in the Experimental folder? Or is it part of the standard stuff now? Thanks!

They are still in experimental, and it might be that I never migrate them to the main toolkit. The thing is, as I’ve developed this toolkit I’ve learned that every new addition I make increases development time on every future feature I want to implement (since I need each new feature to work with every old one).

To combat this issue while still adding new cool stuff I’ve added the experimental folder (in addition to the example maps). The things in this folder range from something interesting that might be a cool starting point to something that is more or less fully functioning, but not something I feel is generic enough to be a part of the base toolkit. The move animation stuff goes mostly in the latter category (except for the climb animation, which is more in the former). As such you should feel free to use the split movement stuff in your game.

The fact that they are in experimental does not mean that they are not usable. If you use them and run into any issues, let me know, and I will provide the same support for these features as I do for the rest of my toolkit.

Hey ,

First of all, great job on this project, I think it’s awesome, too bad I am probably too noobish (or too tired after work) to fully understand how everything is connected.

My first problem is as follows: I am trying to make some traps and I want the traps to deal damage, but not end movement. After watching the tutorials, I split it into simulation and animation, etc, and it works, whoever walks into them takes damage. It mainly works well, unless there is only an AI and a player controlled unit remaining. Then, if the player-controlled unit dies on movement while walking the traps, the game enters an infinite loop and exits (it calls RunOnActorSelected on the AI unit forever, though the game should have ended). If the AI unit dies from traps when moving, the remaining player unit can stroll around indefinitely, and the end game is not triggered.
This behaviour does not happen if there are also other units, it only happens on last kill made by my traps, kill that would otherwise trigger end game.

So, I am pretty sure I am doing something wrong, but I’ve been investigating this for some time, and still I don’t have the faintest idea what. I will upload my blueprints screenshots, and hope you can help me :slight_smile:

Second thing: I am curious how/if a ready-action/shoot-on-sight ability could be implemented. I admit not having seen all of the video tutorials, I got stuck on problem 1, but I like to think about the future as well.

Third thing: is there an API kind-of-thingie? A document describing the parameters for various stuff (I am mostly thinking about the QueueAction macro here), and I always try to remember, open all the blueprints, or open the video.

Looking forward to hearing from you,
Thanks

Hey Valmuadib, no need to feel stupid when it comes to this particular issue, that is for sure. Actions interrupting movement is one of the things I’ve personally struggled the most with when it comes to finding a clean and generic implementation. As you have noticed it is particularly problematic when it comes to a unit dying on its own turn, and particularly if that death also leads to game over. However, the last update was (among other things) an attempt to fix these issues, and you’ll find that there is both a spike trap and an Overwatch shot ability in the Maps - Experimental folder. These are exactly the two things you say you’re after, so check them out and see if they solve your problems.

Your code looks good from what I can tell, by the way. The issue does not lie in your specific code, but rather how unit death and Game Over is handled. If you’re using the very latest version I’m not sure why your solution does not work while mine does. I’ll have to check my code to figure that out, but I’m still on vacation away from home for another week.

Well, that is a welcome new lead, going to check that right now :slight_smile: And I am pretty sure I have the latest version, but will double check that as well.

Have a great week then! :smiley:

It’s all good. I need to get more in depth into the code structure anyhow. Sometimes I get lost lost in there when trying to add new things and stuff. Mainly I wanted you to be aware that if action points was left on last unit in game and it was run by AI, the Game Over message would never happen. And it is always possible I changed some code somewhere that made that happen also, but that code I added in probably wouldn’t hurt to add anyway. So you might check it out when you have time.

And also, enjoy your vacation!

Heya ,

Where does the AI actually call the 3 AI choices you have? I am guessing all the AI is in C++ or something. Do We have accessibility to that code. The AI works fine for basic units in my game, but for Hero Units need to have more complex AI to hunt or worry about other Hero Units and other specific AI for certain circumstances. Could we have a AI system similar to your Ability system at some point? Where we can add a AI and be able to edit what it does. and assign our specific AI to that unit.

Thanks, Loco