Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[RELEASED] Turn Based Strategy Framework

Discussion in 'Assets and Asset Store' started by michal-zetkowski, Jul 2, 2019.

  1. jaycgolden

    jaycgolden

    Joined:
    Jul 19, 2019
    Posts:
    3
    Thanks for your reply~~
    1) I set the boolean in Animator call "is Running":
    upload_2020-4-24_18-0-35.png
    I prefer if it become "true", will show "running"

    and the code in "MyUnit.cs":

    Code (CSharp):
    1.        public override void Move(Cell destinationCell, List<Cell> path)
    2.         {
    3.  
    4.          
    5.          
    6.             JayAnim = this.GetComponentInChildren<Animator>();
    7.             JayAnim.SetBool("isRunning", true);
    8.             Debug.Log("here");
    9.  
    10.          
    11.             {
    12.                 Highlighter.gameObject.SetActive(false);
    13.                 base.Move(destinationCell, path);
    14.             }
    15.          
    16.         }


    But not sure why it cannot show the "running" on time....and only can appear "running" animation after It arrived the destination......:(:(:(

    upload_2020-4-24_18-4-16.png upload_2020-4-24_18-4-28.png
    upload_2020-4-24_18-4-37.png
     

    Attached Files:

    Last edited: Apr 24, 2020
  2. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Your code looks right. Could you export your project and send it to me by email to crookedhead@outlook.com? I would take a look at it and post a reply here.
     
  3. jaycgolden

    jaycgolden

    Joined:
    Jul 19, 2019
    Posts:
    3
    Thanks a lot for your kindly help, I just sent the project to your email.:)
     
  4. mariuszonik

    mariuszonik

    Joined:
    Jan 21, 2017
    Posts:
    2
    In each of your example scenes, the units and players are defined before the game starts, how can I implement the scenario in which the unit type, how many units and their location on the map are dynamically loaded? I mean, the player moves on the map with enemy icons, if he gets close to them a new scene is loaded with a random set of enemies. Is the AddUnit() method a good direction to solve this problem?
    Sorry for my english, best regards
     
  5. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Yes, if you want to spawn units on runtime then using CellGrid.AddUnit method is the way to go. First, instantiate your unit prefab, assign a cell to the unit (through unit.Cell), and then pass its Transform component to AddUnit. The method will wire up all the events necessary for the unit to work.

    If you have any issues with using AddUnit, let me know.
     
  6. GenEmm

    GenEmm

    Joined:
    Mar 22, 2013
    Posts:
    8
    Hi,

    Can the system be customized wherein:

    0. there will be 4 variables added which are the team1unit_designated_movement, team1unit_designated_action, team2unit_designated_movement, and team2unit_designated_action

    1.1. team1 unit will normally do movement and action but after it is done the movement and action will be saved in the custom variables team1unit_designated_movement and team1unit_designated_action then the position of team1 unit will be reset prior the normal movement and action

    1.2. do the same to team2 unit but for team2unit_designated_movement and team2unit_designated_action variables then also reset team2 unit position

    2. apply the saved movement and action values of the 4 custom variables in team1unit_designated_movement, team1unit_designated_action, team2unit_designated_movement, and team2unit_designated_action at the same time for both team units

    3. Next turn

    Will it be possible? So it will be like this:

    1.1. [Plan] Move, act, save (movement and action), and reset the position of team 1 unit
    1.2. [Plan] #1.1. but for team 2 unit
    2. [Execute] apply saved #1.1. and #1.2.
    3. Next turn

    or something similar to it...
     
  7. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, so as far as I understand, you basically want to split "plan" and "execution" phases. I never done it, but I imagine it could be done by modifying CellGridState classes. For example, right now, when you select a unit and click on a cell, CellGridStateUnitSelected class makes the unit move to selected cell immediately. Instead, it should encapsulate the move in an object and put it in a list. At the end of a turn all the moves / attacks stored in the list could be executed.

    That is the way I would approach it, let me know if you need more details.
     
    GenEmm likes this.
  8. mariuszonik

    mariuszonik

    Joined:
    Jan 21, 2017
    Posts:
    2


    Thank you very much, I tested and works, best regards
     
  9. GenEmm

    GenEmm

    Joined:
    Mar 22, 2013
    Posts:
    8
    I will only be able to test it if I buy the framework, right? If ever it won’t work, will I be able to refund it?
     
  10. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    Over the last couple of years I had about 3 refund requests and all of these users messaged me a short time after buying, claiming that the Framework was not suitable for their needs. I refunded them without a question, but I would like to keep it to a minimum.

    I prefer to discuss any doubts with customers before buying, so thanks for asking. To sum up your previous question, the feature that you ask for is not available out of the box. It would be moderately easy to implement it. You would have to do it yourself, but I am always happy to provide support with any issues.

    With that being said, I think that this case would not qualify for a refund.
     
    GenEmm likes this.
  11. ZDMGames

    ZDMGames

    Joined:
    Nov 6, 2019
    Posts:
    7
    I need a little help with adding units in game. I keep getting some errors with it. The most noticeable thing is that the cells they are spawned on aren't being marked as taken and I think there might be more under the hood.
    Here is the lines that are supposed to add them in after being instantiated.

    unit.GetComponent<CombatUnit>().Cell = hit.collider.gameObject.GetComponent<CombatCell>();
    grid.AddUnit(unit.transform);

    the unit is the instantiated unit and the grid is my reference to the grid. Also getting weird bug when clicking on anything.

    NullReferenceException: routine is null

    Any help would be appreciated
     
    Last edited: May 15, 2020
  12. GenEmm

    GenEmm

    Joined:
    Mar 22, 2013
    Posts:
    8
    I understand. If that is the case, may I ask for your help on how to quite start implementing my goal in your framework so that I can verify that it is possible before I buy it.
     
  13. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    The part where you add unit seems good, but could you try adding the following line also?

    hit.collider.gameObject.GetComponent<CombatCell>().isTaken = true;

    Also, could you tell where this NullReferenceException is comeing from? Seems to me like some error in unit initialization perhaps?
     
  14. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Well, I outlined the solution in previous post, I can try to give you some more technical details.

    To encapsulate the actions you would need to write some simple interface, something like this:
    Code (CSharp):
    1. interface UnitAction
    2. {
    3.     void Execute();
    4. }
    The interface would have two implementations:
    Code (CSharp):
    1. class MovementUnitAction : UnitAction
    2. {
    3.     private Cell destinationCell;
    4.     public Execute()
    5.     {
    6.         //Move to destinationCell
    7.     }
    8. }
    Code (CSharp):
    1. class AttackUnitAction : UnitAction
    2. {
    3.     private Unit unitToAttack;
    4.     public Execute()
    5.     {
    6.         //Attack unitToAttack
    7.     }
    8. }
    As I said, in current implementation in CellGridStateUnitSelected class, when you select a cell to move to or unit to attack, the action is performed right away. Instead of that, you would need a list of UnitActions that you would use to store the actions instead of performing it immediatelly. When the turn is over, you would loop over all the Actions in the list and use Execute() method to perform them.

    As you asked, that would be a start.
     
    GenEmm likes this.
  15. ZDMGames

    ZDMGames

    Joined:
    Nov 6, 2019
    Posts:
    7
    It seems to be coming from the unit. It's pointing to this in the error.
    public void SetState(UnitState state)
    {
    UnitState.MakeTransition(state);
    }
    Also noticed that the unit isn't a child of the units object. Is that important?
     
  16. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    UnitState is assigned in Initizlize method, if you're getting NullReferenceException then it seems that Initialize is not called. Could you try calling it manually after instantiation?

    It is important that unit is child of units object when you create units "statically", before runtime. If you instantiate unit at runtime and call AddUnit manually, it should not make any difference.
     
  17. ZDMGames

    ZDMGames

    Joined:
    Nov 6, 2019
    Posts:
    7
    Attempted to initialize, but nothing changed. Same error popped up. If you want to take a closer look at it is doing, I can try to pack up the files and send them your way.
     
    Last edited: May 17, 2020
  18. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Could you export your project and send it to me by email?
     
  19. ZDMGames

    ZDMGames

    Joined:
    Nov 6, 2019
    Posts:
    7
    Sure thing. Just give me a little bit to add some comments in to help make it easier to track what is going on

    Update: Email sent
     
    Last edited: May 18, 2020
  20. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    For anyone interested - the issue was that Initialize method was not called (I believe this is a bug, I will add a call to Initialize in AddUnit method in future release) and secondly, there was no collider on the unit (I will add some warning that Unit / Cell has no collider in the furure release)
     
  21. GenEmm

    GenEmm

    Joined:
    Mar 22, 2013
    Posts:
    8
    I just bought your TBSF asset and opened it in my Unity.

    I got errors, here:

    upload_2020-5-24_22-18-25.png

    Any idea how to fix the errors?
     
  22. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    I got the same issue when tried to import the project with this Unity version, but the project was still imported correctly. Alternatively you can click 'skip' when prompted for installing dependencies. I will probably need to take a lok at these dependencies and upload the project for each new Unity version separately to avoid such errors.
     
  23. GenEmm

    GenEmm

    Joined:
    Mar 22, 2013
    Posts:
    8
    This is what is displayed now in my end:

    upload_2020-5-25_12-31-11.png
     
  24. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    What happens when you select Quit / Continue? Did you try removing com.unity.package-manager-ui@2.1.2 from manifest.json manually?
     
  25. GenEmm

    GenEmm

    Joined:
    Mar 22, 2013
    Posts:
    8
    I renamed the filename to manifest-original.json then clicked Continue. Then it created another manifest.json and opened the Unity software with only 1 error left among the 3 previous errors. The error left is the red octagon exclamation symbol.

    Then a window comes up. I chose skip. I closed Unity and reopend it but I encountered this other screenshot:

    upload_2020-5-26_14-21-31.png

    Although, I have already allowed UnityPackageManager.exe to pass through the firewall. Any idea what to do?
     

    Attached Files:

  26. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Not really, but please contact me by email (crookedhead@outlook.com) and I will try to fix the packages on my end, export the project with Unity version that you use and send it t you.
     
  27. dmattox10

    dmattox10

    Joined:
    Oct 26, 2013
    Posts:
    10
    I cannot use the grid helper. I get the error "invalid hexagon prefab provided" and a null reference error on GridHelper.GeneratebaseStructure(). My cell prefabs are a 2d sprite with the MyHexagon code from example2 attached to it, as well as a circle collider. I included an empty "Highlighter" game object as a child.
     
  28. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    In the code the following fragment is responsible for showing the message that you are getting:

    Code (CSharp):
    1. if (HexagonPrefab.GetComponent<Hexagon>() == null)
    2. {
    3.     Debug.LogError("Invalid hexagon prefab provided");
    4.     return null;
    5. }
    My best guess at this point is that the prefab that you provided does not have a script derived from Hexagon attached to it. Could you post a screenshot of your prefab and its components?
     
  29. dmattox10

    dmattox10

    Joined:
    Oct 26, 2013
    Posts:
    10
    My script starts with: public class MyHexagon : Hexagon
    included is a screenshot of the prefab, thanks!

    I'm using the latest "release" version of unity, if that helps at all.
     

    Attached Files:

    Last edited: Jun 1, 2020
  30. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    Wow, this looks fantastic. A quick question, if I could get your opinion. I have been looking to create a game similar to an old 80's game called Empire Deluxe (https://en.wikipedia.org/wiki/Empire_(1977_video_game). The Mapping system has always been my downfall, especially considering I would like to use Hex Shaped Cells. Would you Consider this an appropriate Asset for my project?
     
  31. ZanesTheArgent

    ZanesTheArgent

    Joined:
    Jul 6, 2019
    Posts:
    2
    Having the same issues as GenEmm but at earlier Unity versions (19.2.20f1), i decided to try and install the package in older versions to check where i could use it properly.
    Will try and place it in a 2018 version, so reporting soon.

    Edit: seems that 19.2.20 actually works but finds the package issues when you import, but has none after you close and open the editor.
     
    Last edited: Jun 1, 2020
  32. dmattox10

    dmattox10

    Joined:
    Oct 26, 2013
    Posts:
    10
    It is indeed my Prefab that is the problem but I cannot figure out for the life of me what the difference between my prefab and yours is. Switching yours out for mine the grid draws. Can I send you my prefab somehow?
     
  33. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Sure, please export your project and send it to me by email :)
     
  34. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, manually removing com.unity.package-manager-ui from Packages/manifest solved the issue for GenEmm. I will upload the project without this dependency to Asset Store in the future.
     
    ZanesTheArgent likes this.
  35. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    I'm not familiar with this game, but by looking at the screenshots I can't see anything that the framework would not handle. Different kind of units, different kind of terrains is what framework does best. Hexagons are also supported of course. If you could describe some specific features that are not obvious from the screenshots, I would be able to provide more detailed answer :)
     
    Last edited: Jun 2, 2020
  36. jbnlwilliams1

    jbnlwilliams1

    Joined:
    May 21, 2019
    Posts:
    267
    It is turn based war strategy game. You start with just a few units, then build more as the game progresses. Move your units onto enemy units to engage combat. Take over city units , were you can then build more units from those. Battles are fought 'to the death', so one unit wins, one loses. You can also stack a certain number of units on a single cell. Other game that is similar is one called Battles of Destiny, Made by Hollistic Gaming.
     
  37. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Currently in the framework a cell can be occpupied by a single unit, but it would be pretty easy to change it. There is no 'building' or 'city' system that would act like unit spawner. Other than that, the framework got you covered. I would be happy to help if you decide to implement these features.
     
  38. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    For future reference - the problem was that part of the code was moved to another namespace. Grid Helper was expeccting TbsFramework.Cells.Hexagon, but was getting <another_namespace>.Cells.Hexagon. That's why "Invalid hexagon prefab provided" error appeared. Changing namespaces fixed the issue.
     
  39. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    Hey there. Loving the asset so far, very well done. I was wondering how you would suggest approaching a "turn" system like Final Fantasy Tactics.

    Basically, in FFT, they have a speed attribute which fills up a "bar". When that bar reaches 100%, it's that units turn. You could have an extremely fast unit take multiple turns before other units get one.

    I've never been a fan of moving all units per turn. Any advice on how to approach this? I was thinking of just adding the "bar" to the unit, and when it reaches 100%, simply change turns to the unit's player. Do you see anything wrong with this?

    Thanks, and thanks for the wonderful asset
     
  40. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    Thanks for the review on Asset Store :)

    Your approach sounds fine, I see the following issues here:
    • You will need to automatically select the unit that is allowed to move this turn - you can do it by assigning CellGridStateUnitSelected object with the unit passed as parameter to CellGrid.GridState. Also, in CellGridStateUnitSelected you will need to disable option to selecting different units - check out CellGridStateUnitSelected.OnUnitClicked
    • Another issue is that you will need to rework AI script. The mechanism is different than for human players. Maybe simply pass the unit that AI is allowed to work with as parameter?
    • Lastly, you will need to rework CellGrid.EndTurn function. The function handles selecting current player and runs OnTurnStart and OnTurnEnd methods on all units that start / end turn. In your case, you will need to run these methods only on a single unit
    I'm sure there will be more things to consider, let me know if you have more questions.
     
  41. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Regarding Triggering character animations - ( as per jcgolden's post in April )

    The developer Michael mentioned he'd post the outcome … but to date nothing. The project was sent but no follow up posted here :(

    I'm looking at triggering unit animations. ie. idle animation / / attack etc.. & if possible
    unit movements

    Are there any posts or tutorials regarding adding animation ?

    BTW... WarTile is coming to Tilt5 !

     
    Last edited: Jun 26, 2020
  42. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
  43. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    War Tile looks pretty cool. Made with TSBF? Well done
     
  44. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Tilt 5 Looks awesome !!
     
  45. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Last edited: Jun 26, 2020
  46. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    This is correct, I had some issues running the project that was sent, we tried to make it work with jcgolden but ultimately it didn't work out.

    Regarding your problem - You can trigger attack / defence animations in Unit.MarkAsAttacking / Unit.MarkAsDefending. As for movement animations, as I said before, you should override Move method and trigger it there (dont forget to call base.Move())

    Please experiment with this and let me know if you have any issues
     
  47. Jon_Brant

    Jon_Brant

    Joined:
    Mar 22, 2018
    Posts:
    56
    Ah, yeah, I saw Dust and Salt before. Tavern Table Tactics looks pretty solid though.

    On that note, I was wondering how you'd suggest approaching targeting spells like that. I'm thinking make a new CellGridState for spell targeting, is that the right approach?

    As for feedback, in a future version I think you should try decoupling the CellGrid class a bit. It does too much at the moment. Also, many of the methods in it should probably be virtual. I'm trying to figure out how to modify it without editing the original code. The rest of the project makes that very easy, but with CellGrid, I'm not seeing many options aside from rewriting it completely, but as cells and units seem to reference it, I'd need to rewrite those too

    I can of course, just make them virtual myself, but then if you release an update, it's game breaking. Also, the docs (or code comment, can't remember) said you were unsure if you wanted to change the CellGridState to another system. At first I agreed, but I think it's good. It enforces good coding practices, I think.
     
  48. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Hi Michael...
    Thanks for the speedy reply.
    R
    egarding triggering Unit animations... I'll look into it today. ​

    Tavern Tactics units are animated as the unit moves to another Cell Grid so it must be possible... unless in TT the dev. simply turned on a way point system that updated a nav. mesh. I feel that would probably be overkill
     
  49. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    Regarding adding my own animated units. ( In Example 1 )

    Currently my unit only faces the one direction. During movement How can I have the unit face in the direction it travels ? So for example if a unit takes an "L" route 3 x straight , 2 x right how to have the unit turn right ?
     

    Attached Files:

    Last edited: Jun 28, 2020
  50. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    376
    I thought this interesting … WarTile's animation setup in Maya ( hit areas)