Search Unity

TowerDefense ToolKit 4

Discussion in 'Assets and Asset Store' started by songtan, Apr 18, 2012.

  1. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    No worries. :)
     
  2. andreigrigore

    andreigrigore

    Joined:
    Jan 23, 2016
    Posts:
    2
    For anybody else having the same issue: I had an animator on the prefab instead of the tower object.

    Thanks for the help and the quick response!
    Much appreciated!
     
  3. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    19
    Hey songtan, picked up your TDTK asset this weekend and have my first level going. Very easy to use asset, I have high hopes. I did come across an issue though.

    I want to introduce each element of the game through a series of tutorial levels. So my first level doesn't have many of the features enabled. I was really happy to discover that the UI you provide as a starter responds to things like the PerksManager being disabled. But I hit a but at the end of the wave, when the player wins:

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. TDTK.PerkManager.WaveCleared (System.Int32 waveIdx) (at Assets/TDTK/Scripts/PerkManager.cs:139)
    3. TDTK.Wave.Cleared () (at Assets/TDTK/Scripts/SpawnManager.cs:375)
    4. TDTK.SpawnManager._CreepDestroyed (TDTK.UnitCreep creep, System.Boolean reachDest) (at Assets/TDTK/Scripts/SpawnManager.cs:308)
    5. TDTK.SpawnManager.CreepDestroyed (TDTK.UnitCreep creep, System.Boolean reachDest) (at Assets/TDTK/Scripts/SpawnManager.cs:292)
    6. TDTK.UnitCreep.Destroyed (System.Boolean spawnEffDestroyed) (at Assets/TDTK/Scripts/UnitCreep.cs:651)
    7. TDTK.Unit.ApplyAttack (TDTK.AttackInfo aInfo) (at Assets/TDTK/Scripts/Unit.cs:455)
    8. TDTK.ShootObject.Hit (UnityEngine.Vector3 hitPos) (at Assets/TDTK/Scripts/ShootObject.cs:276)
    9. TDTK.ShootObject.Update () (at Assets/TDTK/Scripts/ShootObject.cs:222)
    The solution is pretty simple, put an IsEnabled() check in the WaveCleared method of PerkManager:


    Code (CSharp):
    1.        
    2. public static void WaveCleared(int waveIdx){
    3.  if (IsEnabled())
    4.  {
    5.  …
    6.  }
    7. }
    Which led to another error and the need for another IsEnabled check like above in CachedProgress.

    Assuming I'm not creating any side effects here can you please include these in the next update?
     
  4. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    Thanks for letting me know and sorry for the trouble. I've gone ahead and apply a fix to the bug. It won't be an issue in the next update.
     
    fgardler likes this.
  5. BunnyViking

    BunnyViking

    Joined:
    Nov 28, 2019
    Posts:
    4
    Does this have the ability for mobs to attack towers ?
     
  6. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
  7. BunnyViking

    BunnyViking

    Joined:
    Nov 28, 2019
    Posts:
    4
  8. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    19
    I would like to use TDTK on a terrain. So far this has worked. I have a terrain, a path, a creep and a tower. However, it appears that the creep moves towards the next waypoint in a straight line. On a terrain with undulations this results in the creep moving through the ground in some places and above the ground in others.

    I an think of a number of solutions for this, the simplest being to set the height of the creep to the height of the ground on each update. I've done this using a separate MonoBehaviour but for some reason this sometimes results in the creep walking "in place", i.e. not moving. I suspect my code is somehow overwriting your move code, which is strange since I'm doing it in LateUpdate:

    Code (CSharp):
    1.          
    2. Vector3 pos = thisT.position;
    3. float height = Terrain.activeTerrain.SampleHeight(pos);
    4. pos.y = height;
    5. thisT.position = pos;
    6.  
    Another option is to call this code in your move code, but I don't really like modifying code in an asset which makes it more difficult to upgrade.

    I did think of putting more points on the path so that it better fit the terrain, but this seems laborious. I could code it but it would still only be an approximation. I'd prefer to have the creep just stay on the terrain.

    So I have a couple of questions:

    1) any idea why creeps sometimes walk in place when I run the code in LateUpdate in a separate MonoBehaviour?
    2) would you be willing to add an (option) to have creeps stay on the terrain (happy to do this for you and send a patch file)?
    3) any suggestions for a different/better solution?

    [EDIT] I tried option 2 - it seems to work better, but at sometimes a creep will suddenly rotate through 90 degrees (facing ground) and then walk on the spot. I'm looking into it.

    Thinking on it, I would love to be able to use a NavMesh agent here. In this case each time the target waypoint is updated I'd update the NavMesh Agent. This would give me some more advantages as I'm using Free Form tower placement, so having creeps able to adapt their routes might be interesting. I'll have a play with this too, but would love any guiding thoughts on this.
     
    Last edited: Dec 14, 2019
  9. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    I ran the setup you described. The problem is the waypoints is on a fixed height, not mapped to the terrain. So if you force the creep to reposition its y-axis position based on terrain, they will never be able to reach the waypoint. Eventually, they just stuck on top of the waypoint.

    An easy fixed to this would be to instead of using your custom script on the creep prefab, just attach it to the child object on the prefab which contain the mesh. Taking the default creep 'Creep_Base' for example, the mesh object would be 'Tank1' (you will probably need to place your target-point of the prefab as a child of the mesh-object so the shoot-object will aim at where the mesh-object is). This way the mesh-object would adjust itself but the root remain on the waypoint height. I should point out that this mean the height has no impact on the actual gameplay. But I recon it shouldn't make a huge difference anyway unless you have some serious elevation in your terrain.

    The other alternative would be mapping the waypoints height onto the terrain. This of course require a lot of extra work.

    Finally unless you are using free form tower placement, I doubt NavMesh is going to be useful here.
     
  10. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    19
    Excellent - that works, thank you again for your excellent support. I figure if I make the target point a child of the model root then the change in the models height will compensate, at least in part for the deviation between path and model height. In my quick tests this seems to work well.

    Question: If I were to add a script to each of the waypoint objects that adjusted their height to that of the terrain would that cause any nasty side-effects you can think of (a quick test seemed to work).

    I'll come back to Nav Mesh another time (perhaps). I am using free form placement. It's not actually part of my game design right now, but it might be interesting.
     
  11. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    It only works if you are using a simple waypoint, not when you are using the whole build platform. A platform would have a lot of sub-waypoints that are generated during runtime. You can't just attach a script to them.
     
  12. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    Hello, couple questions.

    When selecting an ability in DragNDrop mode, it appears to respond on MouseDown, allowing you to click and drag to where you want to drop the ability. For towers, however, it appears to be on MouseUp, so you have to click the button, and then click the tower and drag it on mobile. Is there a way to make the tower buttons act the same as the ability buttons, and just attach the tower to your finger on MouseDown, removing the need for a second click?

    Also, if I select an ability, then go select a tower, it keeps both active, so you get a tower with the ability effect around it. Is there a simple way to disable the ability when you click on a tower?

    Thank you!!
     
  13. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    It's an oversight from my end for both the issues. Please send me an email so I can send you the fix.
     
  14. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    Thank you, that fixed both issues!!

    Another thing I noticed, the custom icon that I set under "AbilityManager" and "PerkManager" keeps getting reset. I've tried all kinds of tricks to save it, but it just doesn't seem to sink in. If I close the scene, and reopen it, they've been reset to the defaults.

    Any ideas on a workaround? Thank you!!
     
  15. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    Thanks for letting me know about the bug. I've just sent another fix to your email.

    Fyi, assign the icon directly to PerkDB or AbilityDB in Resource folder should solve the problem.
     
  16. MarvinH

    MarvinH

    Joined:
    Jul 18, 2012
    Posts:
    3
    Hi Songtan!

    Thank you for putting this kit together. Loving the functionality. My design calls for the player to be able to click and command certain towers to move. This is simillar to most (90's Style RTS games. I looked at the Unit.CS code, but where is selection handled?

    In a protoype I made on my own, I clicked a unit, that unit was stored in some type of list of selected units, If that list had a unit in it, the next right mouse button click would move the selected unit to the clicked location. Is this possible in TDTK? Which scripts contain the unit selection code, and player input? (Clicks)
     
  17. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    Thanks for using the framework and I'm glad that you like it. However, I should point out that the tower are not really designed to move in TDTK unless you are using free-form placement. Even with that, there's no collision detection. The creep can move right through them if you move them into the path. Having said that, there's nothing to stop you if you want to move them anyway.

    Just fyi, The script that detect all player input and select unit is UIControl.cs. You will also have to deal with SelectControl.cs and UITowerSelect. Those two are responsible for all visual elements on displayed when a tower is selected.

    Hope this helps.
     
    MarvinH likes this.
  18. MarvinH

    MarvinH

    Joined:
    Jul 18, 2012
    Posts:
    3
    Thanks! Looking into this now. One clarification, I'm basically trying to make traditional units, not so much towers. Are towers parented to the location that they are instantiated on?
     
  19. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    Not really. Both the towers and creep works like a typical RTS unit in every respect except when it comes to movement. The creep is set to look for a move along the shortest path to their destination where the tower are stationary. In non-free-form placement, each tower is tied to a build-point. A build-point would block the creep if it's set as a waypoint and built on.
     
  20. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    19
    I'm having some trouble with the Perk Manager. I believe it's a bug. To repro..

    1. Starting from a demo scene, do lots of customization, including adding 4 new towers in slots 1..4 (i.e. move them to the top of the list)
    2. Everything works fine with only my towers enabled, the ones that came with TDTK are turned off
    3. Turn off towers 2, 3 and 4 in the Tower Manager
    4. Create three perks to enable towers 2, 3 and 4
    5. Start game and buy a perk
    6. If I buy the one that is supposed to enable tower my tower 2 I get the Cannon tower which is now in slot 6 (originally in slot 2 before I added my towers), same happens for each of the other perks

    I believe the problem is in the way the Perks handle tower identifiers. Line 253 of Perk.cs uses newTowerPID which is set to the index of the tower in the ordered list of towers. This is passed to the AddBuildable method in TowerManager.cs, however, this method seems to expect the prefabID. This is not the same as the index in the towerlist.

    I note there is a `ResetPrefabID()` method that will force the PrefabIDs to match the index via the editor context menu, but I'm not sure what side effects this might have.
     
  21. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    You are absolutely right. The bug is in the editor, which use the index of the tower in tower-list rather than the towers prefabID.

    I've fix the bug and I'll do an update shortly but please send me an email if you want the fix in advance.

    You can use ResetPrefabID(). But doing that will break the connection of the towers with anything associated with it (perk, availability in each scene and so on). I wouldn't recommend that unless you are at the very early phase of development where you are just setting up towers.
     
  22. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    19
    Thank you Songtan, I'd love the fix. I'm not sure of your email so I'll PM you and give you mine.

    You and your asset are awesome. OOTB it works (with occasional edge case bugs - as all software has). The code is sufficiently well written that I can understand it and adapt it and your support is significantly better than average. I will say this as often as I can so that people making a buying decision do not hesitate.

    Keep up the good work.
     
    Last edited: Dec 21, 2019
  23. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    Thank you. Just for your information, you can find my email either in the drop down menu (look for Tools), or in the documentation.
     
    fgardler likes this.
  24. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    Thank you for the perk and ability icon fix. They worked great.

    A couple other things that I'm seeing:
    • The audio that I set for "Sound On Activate" under the Ability Editor doesn't seem to play when I use the ability. When I Debug.Log 'soundOnActivate' in Ability.cs, it comes up Null. Am I doing something wrong?
    • On mobile, when you first click an ability, the tooltip immediately pops up. With the towers, however, it doesn't. You can slide the tower away, then back over the icon, and it will show the tooltip, but it doesn't act the same way as the abilities and show it immediately on click. Your other fix for immediately selecting a tower worked great, and brought me to see this next possible bug with the tooltip.
    Thank you for all your work on this great asset!!
     
  25. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    19
    I think I may have found (and fixed) a small bug. I created my first resource tower that was supposed to provide 1 per second of one of my resources and 0 of the other. I quickly noticed that it was adding 2 of the first and 1 of the second. I believe this is a bug in line 533 of Unit.cs. In the current release this says:

    Code (CSharp):
    1. list=RscManager.ApplyModifier(list, activeEffectMul.stats.rscGain);
    Note it is passing the effect multiplier but calling the ApplyModifier method. The multiplier is { 1, 1 } which with my towers {1, 0} I get a result of {2,1}. The same behavior is observed with the example resource tower you provide.

    My problem is fixed by changing the above line to:

    Code (CSharp):
    1. list=RscManager.ApplyMultiplier(list, activeEffectMul.stats.rscGain);
    I've not worked out what the next line does (534 in Unit.cs) but from the variable and method names I think it may have a similar problem - I'm not sure about this one though.
     
  26. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    @nnoom1986, I've tweaked the code on build buttons so it works the same way as the ability button. The ability audio not playing is definitely a bug. I've fixed that and uploaded another update.

    @fgardler, Thanks for letting me know. You are right in both cases, both line533 and 534 needs to be changed to ApplyMultiplier. Just fyi, this has been fixed in the latest update.
     
    nnoom1986 and fgardler like this.
  27. fgardler

    fgardler

    Joined:
    Jun 11, 2016
    Posts:
    19
    @songtan your latest update has broken resource towers. The error is in the code I highlight above (Unit.cs 534).

    Modifying 533 as described above works fine, but modifying 534 results in zero resource additions.This line calls `GetMulUnitRscGain` in PerkManager.cs. This code appears to be applying modifiers not multipliers, hence I believe the second line discussed above (534 in Unit.cs) should not be calling ApplyMultiplier, but rather ApplyModifier (certainly this makes the towers work again).

    I'm not 100% sure about this as I'm still learning your code and in this case the naming seems confused (which isn't typical of your code :)
     
  28. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    Thanks again for point this out. I'm fairly sure the code in Unit.cs is correct. The problem is PerkManager.GetMulUnitRscGain() should have return a multiplier instead of a modifier (yes it's bug atm, my bad). I've fixed it and send a package to your email. I'll upload the fix shortly.
     
    fgardler likes this.
  29. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    Hey @songtan, thank you for the official update! That resolved the majority of my issues, including Perk and Ability icon saving, and the audio for the abilities not playing.

    On this one though, "I've tweaked the code on build buttons so it works the same way as the ability button," I'm not seeing any difference. The tooltip still doesn't show unless you hover over the towers a second time on mobile. Do I need to do anything additional to set that up?

    Thank you!!
     
  30. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    I'm now sure why that's the case to be honest. The build button are using the exact same code as the ability button. However here's a quick fix for the issue: Add OnHoverBuildButton(butObj); in the function OnBuildButton() in UIBuildButton.cs. Anywhere after the first line (line 117) will do.
     
    nnoom1986 likes this.
  31. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    No worries, @songtan, you've been a huge help! I see the fix that you put in, and I see how this one would work if that one didn't, but for some reason, it still doesn't do it. There must be something somewhere else that's killing the initial popup when a tower is selected. No worries if we can't get it working right away. I'll peek at the code when I get a moment and see if I can spot what's happening. In the meantime, if you have any other ideas, lemme know. Thank you!!
     
  32. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    Strange. The quick fix works for me when I test it on my device. My guess is something else is probably calling UITooltip.Hide() after OnBuildButton(). Maybe you can place a debug message there to see if that's the case and what is calling it.
     
    nnoom1986 likes this.
  33. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    Correction, I must have jacked up my build earlier, because the hover tooltip on towers actually IS working, now. Thank you!!
     
  34. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    38
    Hi there. I own the TDTK3, is there any upgrade discount to get 4 by chance?
     
  35. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    I'm sorry but due to limitation of the store system, the upgrade price are fixed. It's not possible to offer any price reduction for any transaction.
     
  36. toddkc

    toddkc

    Joined:
    Nov 20, 2016
    Posts:
    38
    You could give me a key :)
     
  37. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    Hey @songtan,

    I noticed that if you select an ability that uses one Select Indicator, and then go straight to choosing another ability that uses a different Select Indicator, it leaves the previous indicator on the screen AND activates the new one.

    To fix this, I added AbilityManager.ClearSelect(); on line 116 of UIAbilityButton.cs, as the first item below the AbilityManager.RequireTargetSelection(idx) conditional.

    If you know of a better way I'm definitely open, but just thought I'd share. Thanks!!
     
  38. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    @nnoom1986, Thanks for pointing that out. Your proposed solution is as good as any.
     
    nnoom1986 likes this.
  39. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    If I disable all abilities (because I want them all unlocked via perks), it leaves the default Button gameObject behind on the screen. Then, when I unlock an ability with the perk, it gives me this error, because it's counting that default Button gameObject as an ability:

    ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.

    I attempted to simply disable that Button from the start, but it relies on it to put the other abilities there as they unlock. Any suggestions? Thanks!
     
  40. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    I just send you a package that should fix the problem you mention. Please try it and let me know if it doesn't work.
     
    nnoom1986 likes this.
  41. nnoom1986

    nnoom1986

    Joined:
    Jan 9, 2018
    Posts:
    10
    It worked!! Thank you!
     
  42. skyleen55

    skyleen55

    Joined:
    Sep 13, 2019
    Posts:
    1
    Hey, is there a way to assign audio mixer to TDTK audio manager? I mean there's a gameobject called audiomanager, i need to set audio files for each action. I've got an audio mixer for game, music etc sound, and i want to assign each sound to an audiomixer group. Thank you!
     
  43. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,451
    I'm afraid not. AudioManager uses it's own audio source to play the sound clip. If you want to use audiomixer to play the sound, you will have to modify the AudioManager.cs. I'm not familiar with audiomixer so I could be wrong but this modification shouldn't be too difficult. In AudioManager.cs, there are function for playing each sound file. What you need to do is simply change this to passing the sound file to audiomixer instead.
     
unityunity