Search Unity

TowerDefense ToolKit 4

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

  1. ionside

    ionside

    Joined:
    Apr 7, 2011
    Posts:
    38
    Hi Song,
    I'm having trouble with the 'Effect On Hit' of the towers. They don't seem to effect target units even when they have no immunity.
    Worked in old TDTK, but not in this v4. I've also tried in the example scenes and doesn't work in there, too.
    I've specifically tested with Stun, Slow, and Damage Over Time effects.
     
  2. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Thanks for letting me know. Unfortunately I'm away from work for a few days. I'll check it as soon as I can.
     
  3. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    @ionside, you are right. It's a bug and fortunately it's easily fixable. In UStats.cs, there's a function UseEffect(). Change it to public bool UseEffect(){ return effectList.Count!=0; }. That should do the trick.
     
  4. ionside

    ionside

    Joined:
    Apr 7, 2011
    Posts:
    38
    Worked a treat, thanks Song!
     
  5. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
    Song, could you go in depth with how perks work. Upgrades and such. Do all perks added add a effect to the tower to accomplish the rise in damage or health, etc?

    Im curious of the void SetupCallback() especially.
     
  6. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Not all perks add effect to tower, only perks with 'ModifyPerk' type modified tower stats. And they don't really add an effect to the tower. The simply add an global multiplier/modifier effect that is applied to tower with ID associated with it. This bring us to SetupCallback().

    In SetupCallback, the function set up all the func delegate accordingly to their perk type. You can see the content in each individual func that it take a prefabID and return the stats if the prefaID is associated to the perk. The prefabID of course being the prefabID of the towers (or ability for that matter).

    This is how it works for example, whenever a tower attacks in, the calculation will pull the damage value from the tower instance. The tower instance will get the base damage value of the tower, multiply/modify by any active effects, then further multiply/modify it by calling the damage related func delegate (passing the prefabID of the tower) of all the active perks, before return it as the effective value.
     
  7. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
    What from the inspector mode shows while in play that the perk has been active and is applied to a tower? Is it the perks stats that is applied to that tower? The perks Effect Stats + Tower Stats?
     
  8. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    The perk stats will never override the tower stats. It only modify the tower's stats. So when a perk is active for a specific tower, it's tower stats + perk effect stats.
     
  9. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
    Thanks Song, and how exactly do the Tower PID List work, is this how Perk manager determines where to apply its stats?

    Im just trying to figure out exactly how it works:
    1. The user purchases the perk MG Tower Upgrade.
    2. This calls _Status Purchase()
    3. Since it was a ModifyTower it then calls this:
    if(type==_PerkType.ModifyTower){// || type==_PerkType.TowerAll){
    PerkManager.AddUnitPerkID(prefabID); SetupCallback();
    4. public static void AddUnitPerkID(int ID){ uPIDList.Add(ID); }
    What exactly is a uPID.List? Is this what tells the game what stats to add to what?

    And what function from Unit/Tower standpoint calls these perks or is it only the callback and thats it?
     
    Last edited: Nov 10, 2018
  10. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    towerPiD in a perk contains all the prefabID of the towers associated to the perk. It's used to check if a perk should be applied to a tower.

    uPIDList on the PerkManager is a list of all the id of the active perks that is intended for tower. This is to narrow down the search (through all the active perks) when a tower is calling PerkManager to check for any stats change.

    Say when a tower wants to get the modifier for its minimum damage, it call GetModUnitDmgMin() on PerkManager, passing its prefabID. The PerkManager then get all the perks intended for towers using uPIDList. Then the tower prefabID will be passed to the perks. The perks will check the prefabID against it's towerPIDList. If there's a match, it will return the damageMin value on the stats, other wise it will just return 0.
     
    Chaz32621 likes this.
  11. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
    Thanks song understand and got it figured out now :)
     
  12. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
    Would love to see this using the new burst and job system :) once there out of preview that would be amazinggg.
     
  13. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    You are right, it's quite interesting. However I'm quite busy with other project right now. I'll definitely check it out at some point in the future.
     
  14. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    Removed comment because its not a TDTK problem it was solved
    solved simple misspelling of a playmaker event Fsm.sendevent("Save") vs Fsm.sendevent("save")
    no error because well i don't know i guess you can send unused events in playmaker
     
    Last edited: Dec 24, 2018
  15. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    Hi,
    I've been adding animations for the tower and the creep. Adding animations to the tower was not a problem, but adding animations for the creep is simply not working for me.

    I have an empty GameObject as the parent A(Unit Creep as a component), a child B which holds the animator (TDUnitController as controller) and a child C (simple sphere) which I wish to bounce around.

    I've looked into the 'unit' script and it appears to look to replace dummyMove in the controller if an alternative is given in the creep editor. However, it doesn't do that in my case. I've also tried to set it as the 'ídle' animation, but no luck there either.

    When I force the DummyMove node to contain the unit's animation rather than the dummyMove placeholder the balls do start bouncing correctly, but of course the towers start bouncing as well.

    I feel that it isn't checking for the animations when spawning the creep, but I'm not sure, do you have any idea what I'm doing wrong here?

    --edit:
    I'm using unity 2018.2.10f1

    Okay, tonight I started it up again trying to decide what to send to you and it ran without issue. I'm still not sure why it didn't earlier.

    I added some debug logs to the _unit_ script yesterday simply checking whether things were triggered and recognised at the start of the wave and it would say Found NO Move animation. However, it does find the move animation for each creep that is spawned right now.

    Code (CSharp):
    1. if (clipMove!=null)             Debug.Log("Found a Move animation!!", gameObject);
    2.             if (clipMove==null)           Debug.Log("Found NO Move animation!!", gameObject);
    Maybe something wasn't updating correctly and closing unity and opening afresh today may have solved it?

    btw how can I send stuff to you at a later time if the need arises? Do I send you an email through your website and reply to your reply?

    Also, could I send you a 'commented' version of your documentation, pointing out where it might benefit from an update, a bit of extra explanation and fix some typos?
     

    Attached Files:

    Last edited: Dec 28, 2018
  16. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I'm not sure what is wrong here. What version of Unity you are using? Perhaps you can send me your model and animation and I'll see if I can make it work.
     
  17. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    Hi, thank you for your quick response! I opened the project again today and it was working without issue. I've updated my post to keep things together.
     
  18. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Please by all mean send me all your feedback regarding the documentation. You have my thanks in advance. You can email me directly. My contact info can be found at the TDTK dropdown menu.
     
  19. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    Hi, sorry for spamming this forum again.
    I think the tower animation transcends from idle to move animation after placing, and never returns to idle. Assuming I edited something by mistake I reimported the package, however, this did not change the behaviour. Maybe, it doesn't overwrite everything?

    Right now I put a workaround in place by reversing the speed condition of the DCUnitController and setting move animations for enemies to the idle slot in the creep editor. This way I can have tower idle animations and creeps still moving around but I'm sure this workaround will bite me at some point.
     
  20. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    After some checking I think I know what is the problem now. The transition of 'idle' and 'move' state of the animator is controlled by the parameter 'speed'. The animator will transit from 'idle' to 'move' state if the value of the parameter is greater than 0.05. Now the 'speed' parameter is only modified by creep when they move (it's set to the actual move speed of the creep, hence trigger the move animation). The problem is I've unintentionally set the initial value of the 'speed' parameter to 1. Therefore the animator of tower is playing the move animation. I haven't realize this because I've never assigned any move animation to my towers and the default move animation doesn't applied to model I use.

    TLDR: I think you can fixed the problem by simply set the initial value of the 'speed' parameter on the animator controller to 0.
     
  21. Ferdi18

    Ferdi18

    Joined:
    Jul 19, 2014
    Posts:
    13
    I saw the speed value in the animator set to 1, but did not want to touch it in the animator itself.
    I'll change it and see if that helps, thank you!
     
  22. Chaz32621

    Chaz32621

    Joined:
    Apr 17, 2015
    Posts:
    198
  23. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    where would i start for making my own creep spawner .. i see a path will need to be assigned... i think the spawn button will need to be active. any tips on how to custom spawn creeps?
     
  24. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Can you be more specific? You want to code your own Spawner? Any reason the default one doesn't work?
     
  25. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    it works fine but im going to need to do it manually they will be even driven for a story line, when i instantiate one and give it a path and press the spawn button still dosnt work for me .. i looked into the "public void _Spawn()" but i haven solved it yet.. looks like there is a list i should deal with,, i need to instantiate one and just have it do what it usually dose.... i can manually instantiate towers and they work fine..i know i say i press the spawn button but i only do it to see if it will trigger it i wanna bypass the spawn button and have a event driven system on a cycle based on time of day and various other reason .. i need to instantiate it and have it do its thing and find the path..
     
    Last edited: Mar 1, 2019
  26. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    mabey i make various waves and save them as prefabs and load them manually when i need them...hhhmm..im sure you know a way to hardwire a creep to works thats simple .. i just dont have a full understanding yet
     
  27. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    If you just want to bypass the spawn button. You can just replace the disable the spawn button. The simplest way would be to move it offscreen so player can't see it. Then you simply call SpawnManager.Spawn(); after your custom spawn condition is satisfied. Make sense?
     
  28. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    i want to instantiate a creep and make him do what ever he would normally do.. outside you spawn system as much as possible. ill look into the spawn manager thing you mentioned
     
  29. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I see. In that case. This is what you need:
    Code (CSharp):
    1. public GameObject creepPrefab;
    2. public Path path;
    3.  
    4. public void Spawn(){
    5.     GameObject unitObj=(GameObject)Instantiate(creepPrefab, path.GetSpawnPoint(), Quaternion.identity);
    6.     UnitCreep unitInstance=unitObj.GetComponent<UnitCreep>();
    7.     unitInstance.Init(0, path);
    8. }
    You can refer to SpawnUnit() in SpawnManager. However it's not just about spawning the creep. By default, each creep is tied to a wave. That info is passed to the creep when calling Init() and used to check if the wave is cleared when the creep is destroyed. In the example code I gave you, I'm use 0. It should work but to make sure it works 100%, you will need to modify _CreepDestroyed() in SpawnManager.
     
  30. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    thanks. thats the magic i was looking for . yeah .. i would go into detail but its a big project multiplayer and crafting inventories making towers and armys.. it gear towards moRTS ..ive abused your code pretty wel to make it fit my needs. i did grab your topdown code and ill give that a look..my game could probaly be swapped into that system easier than what im doing here now but its fun,
     
  31. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi, Using projectile.
    what's wrong?

    NullReferenceException: Object reference not set to an instance of an object
    TDTK.ShootObject.OnEnable () (at Assets/TDTK/Scripts/ShootObject.cs:87)
    UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion)
    Pool:Spawn(Vector3, Quaternion) (at Assets/TDTK/Scripts/Utility/ObjectPoolManager.cs:142)
    ObjectPoolManager:_Spawn(GameObject, Vector3, Quaternion, Single) (at Assets/TDTK/Scripts/Utility/ObjectPoolManager.cs:71)
    ObjectPoolManager:Spawn(GameObject, Vector3, Quaternion, Single) (at Assets/TDTK/Scripts/Utility/ObjectPoolManager.cs:55)
    TDTK.<Shoot>c__Iterator1:MoveNext() (at Assets/TDTK/Scripts/Unit.cs:362)
    UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

    Sorry for my English
     
    Last edited: Mar 11, 2019
  32. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    The projectile after the acceleration of time is not destroyed does not damage, the game speed by default, everything works. What can be wrong?

    Sorry for my English
     
  33. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Have you made any modification to the code? I notice the error message doesn't quite match the code that I have. Also are you using your own custom projectile? Does the default projectile has the same problem?
     
  34. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Сhanges only in PerkManager, RscManager, TDSave, and they were for saving.

    ShootObject.cs script did not change
    script did not change.


    Yes, with the original projectile is the same. This problem with Missile. When accelerating time, Missile fly behind the target without causing harm or exploding.

    At normal game speed, everything works.

    Sorry for my English
     
  35. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    If you are still experiencing that error you mention earlier? What are the time-scale you are using when speeding things up? And what version of TDTK you are using exactly? Can you send me your ShootObject.cs? Maybe the shoot-object prefab in question too.

    I've got I tried and everything works fine on my end.
     
  36. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    version TDTK v4.0.1 f2
     

    Attached Files:

  37. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I'm not quite sure what's wrong. There seems to be nothing wrong with the code you are using and everything seems to be working fine when I'm testing. I'm not sure if you are still experiencing the error but as far as I can tell it shouldn't break anything.

    What I would suggest is to either slow down the time acceleration or the projectile speed. Using a very high speed could sometime cause problem.
     
  38. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    How to slow down time acceleration? Where to change the value?
     
  39. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Asset Store downloaded your prefab projectile, there is no error, but when you accelerate the time, the rocket will still fly for the target, there is no damage, no destruction. Projectile speed 40
    Cooldown 1
     
  40. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Tower settings
     

    Attached Files:

  41. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I tried what you described, setting the projectile speed to 40. I even up the speed in time-acceleration. Still works fine. I suspect it's something to do with the prefab you are using.

    Anyway, you can try change the time-scale used for time-acceleration in UIHUDButton.cs, line106.
     
  42. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    so you gave me some custom spawn code and it works, i went and started adding towers and discovered that they do not target the manual spawned creeps, do you know how to make them targets to the towers?

    Code (CSharp):
    1. public GameObject creepPrefab;
    2. public Path path;
    3. public void Spawn(){
    4.     GameObject unitObj=(GameObject)Instantiate(creepPrefab, path.GetSpawnPoint(), Quaternion.identity);
    5.     UnitCreep unitInstance=unitObj.GetComponent<UnitCreep>();
    6.     unitInstance.Init(0, path);
    7. }
     
    Last edited: Mar 13, 2019
  43. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Sorry, I missed one thing. You have to add the creep to a list tracked by the tower's targeting. It's simple, just add this line at the final line of your function:

    SpawnManager.AddActiveUnit(unitInstance);
     
  44. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    sweet i want to make a system were your protecting a fleet and there are pirates you have to defend against.. i wont add the resupply fleet to the list this works out great
     
  45. wethecom

    wethecom

    Joined:
    Jun 24, 2015
    Posts:
    71
    maybe you could expand the abilities of the game to allow if some ships make it they help and give health and make a flag for making them the enemy or friendly .im going to put this in my code but you know .. i figured i would say somthing to try make your code versatile
     
  46. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hello.
    Tdtk 4.0.3 f1 Working in Unity 2018.3.8?
     
  47. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    Yes. The latest version should support Unity2018.3.
     
  48. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Hi

    Unity 2018.3.8

    Empty project, download from TDTK 4.0.3 f1 asset. There are no errors, but I make a build, three errors.

    Assets\TDTK\Scripts\DB\Creep_DB.cs(29,13): error CS1061: 'Creep_DB' does not contain a definition for 'FillObjectList' and no accessible extension method 'FillObjectList' accepting a first argument of type 'Creep_DB' could be found (are you missing a using directive or an assembly reference?)

    Assets\TDTK\Scripts\DB\Tower_DB.cs(29,13): error CS1061: 'Tower_DB' does not contain a definition for 'FillObjectList' and no accessible extension method 'FillObjectList' accepting a first argument of type 'Tower_DB' could be found (are you missing a using directive or an assembly reference?)
     
  49. alexsander890

    alexsander890

    Joined:
    Apr 15, 2013
    Posts:
    61
    Unity 2018.3.0f2


    Also, the new project is empty, from TDTK and Asset Store is loaded I do the build, errors.

    Assets\TDTK\Scripts\DB\Creep_DB.cs(29,13): error CS1061: 'Creep_DB' does not contain a definition for 'FillObjectList' and no accessible extension method 'FillObjectList' accepting a first argument of type 'Creep_DB' could be found (are you missing a using directive or an assembly reference?)

    Assets\TDTK\Scripts\DB\Tower_DB.cs(29,13): error CS1061: 'Tower_DB' does not contain a definition for 'FillObjectList' and no accessible extension method 'FillObjectList' accepting a first argument of type 'Tower_DB' could be found (are you missing a using directive or an assembly reference?)

    Error building Player because scripts had compiler errors

    Build completed with a result of 'Failed'
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00234] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:190
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:96
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    Sorry for english
     
  50. songtan

    songtan

    Joined:
    Apr 9, 2011
    Posts:
    2,404
    I've a fix that I'm about to upload that should fix the errors. Shouldn't take more than a day or two.

    If you want, you can email me and I can send you the fix in advance.