Search Unity

Core GameKit! Pooling / Spawning / Combat

Discussion in 'Assets and Asset Store' started by jerotas, Jan 27, 2013.

  1. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    About your edited part, the Prefab Pool items' Active criteria are only evaluated each time the pool refills (not every time you grab a random item), so that won't work right. I'll send the info about subclassing shortly.
     
  2. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Here, make a subclass like this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class TriggeredSpawnerSubclass : TriggeredSpawner {
    6.     public Transform prefabA;
    7.     public Transform prefabB;
    8.    
    9.     protected override Transform GetSpawnable(TriggeredWaveMetaData wave)
    10.     {
    11.         if (true) { // change "true" to your logic check
    12.             return prefabA;
    13.         } else {
    14.             return prefabB;
    15.         }
    16.     }
    17. }
    And remove the Triggered Spawner component, and add this Triggered Spawner Subclass instead to the game object, then set up the waves again in the Triggered Spawner. As long as you are on Unity 4+, the custom Inspector will still work.
     
  3. Maindric

    Maindric

    Joined:
    Nov 25, 2012
    Posts:
    15
    Thanks for that! Works perfect.

    I took your method, and developed it a little bit differently. I am using Playmaker to activate when the units spawn.

    I use playmaker to pass the GameObject I wish to spawn, then call the trigger spawn method to actually spawn the unit. I also am using a World Variable NumToSpawn to spawn the specific number that I wish.

    Here is the final code:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CustomTriggeredSpawner : TriggeredSpawner
    5. {
    6.     private Transform unitToSpawn;
    7.  
    8.     protected override Transform GetSpawnable(TriggeredWaveMetaData wave)
    9.     {
    10.         return unitToSpawn;
    11.     }
    12.    
    13.     public void SetUnit(GameObject unitSpawn)
    14.     {
    15.         unitToSpawn = unitSpawn.transform;
    16.     }
    17.  
    18. }
    Once again, thank you for the A+ support!
     
  4. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Cool, then you're sorted :)
     
  5. dev_2051

    dev_2051

    Joined:
    Jul 25, 2013
    Posts:
    92
    Hi Brian,

    Is it possible to attach a monobehaviour function on wave spawn finish event?:confused:
    Like how NGUI has on finished action on tweens binded through delegation.This will give the ability to handle some GUI trigger notifications whenever new wave is spawning.:idea:

    Thanks.
     
  6. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Yes, are you using the global waves, or do you want to do something at the beginning of a triggered spawner's wave?

    If the former, use the LevelSettingsListener, WaveStarted method to call your code.
    If the latter, use the TriggeredSpawnerListener, WaveStart method to call your code.

    There's also events in there for Wave Ended. And there is also the Playmaker versions of these Listeners where you just point to an FSM and a state to execute as well, with no code to write :)
     
  7. dev_2051

    dev_2051

    Joined:
    Jul 25, 2013
    Posts:
    92
    thanks this is exactly what i was looking. :)
     
  8. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Cool.
     
  9. ChaneDev

    ChaneDev

    Joined:
    Feb 12, 2013
    Posts:
    66
    After getting the latest update (Unity 4.3.4f1) I no longer have the Core Gamekit banner and I don't have the create LevelWaveSettings button on the prefab. Not sure if you or anyone else is seeing this. I deleted the previous version of Core Gamekit before importing the newest version. Not a huge deal, just thought you should know, or to see if I broke something.

    $Capture.JPG
     
  10. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Do you have the folder: Assets\Editor Default Resources\Core GameKit ?
    If not, please re-download the package from the store. I see on the Asset Store page that that folder exists. If you have the file "inspector_header_killer_waves.png" anywhere else, please delete it and the entire folder it's in before you reimport.
     
  11. ChaneDev

    ChaneDev

    Joined:
    Feb 12, 2013
    Posts:
    66
    Thanks for the tip, yeah I had that folder left behind. I think it was because I am test driving the Unity Asset Server and didn't commit the deleted package first to the server before importing the new version.

    Alright back to rocking the ON switch!
     
  12. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Nah, that shouldn't matter. You must have had some files somewhere you didn't delete. Anyway, you're good now!
     
  13. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hello jerotas
    i finally try to put my hand into gamekit, and so far it look pretty powerfull, i still got to learn few thing with global variable as in your exemple you have health and live variable, was wondering if it has some connection with the killable script variable of HIT that you need to setup, how do i know and trigger a message that my player is dead? so i can trigger my gameover scene.

    also you use player pref and i own an asset that protect the player preferences from pirate , can i use this with your gamekit?

    any hint would be helpful.

    thanks
     
  14. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    We use only a cached version of PlayerPrefs, not the normal one. Hundreds of times faster. So no, you can't use your anti-piracy PlayerPrefs plugin with this.

    Normally you would use a "Lives" variable and when it hits zero, you can use a LevelSettingsListener, use the GameOver event and make sure you set the Lives variable to "Triggers Game Over". Then you can add code to "GameOver" event.

    Notice I've said nothing about hit points. I don't see where that is a factor?
     
  15. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    oh i see, will test this out then, for the killable HIT point variable, i thought it connect to the health point so when it reach 0 your live would automatically substract-1
    does it make sense? or it s something i had to setup?
     
  16. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    If you want to use a variable for the Hit points, it will only read that variable when the prefab spawns (starting value only). When the Killable dies, you can make it -1 to the lives with the World Variable Modifiers section.
     
  17. Fahrettin

    Fahrettin

    Joined:
    Mar 10, 2014
    Posts:
    81
    First thanks for this asset. If it can be used successfully it has perfect potential.
    I have a noob question because i am noob :)
    I read the document and spawned objects. I have simple game project in my head. Its like your "Triggered Spawners" ex scene but i want to destroy objects with touch. Can you help me to achieve this or show me the way.
     
  18. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    That's on the to-do list actually. If you have an input package such as FingerGestures or Input.Touches (or make your own script) you just need to make it so when you tap the object, it calls the Killable component's DestroyKillable method (to kill it).
     
  19. Fahrettin

    Fahrettin

    Joined:
    Mar 10, 2014
    Posts:
    81
    I dont have any input packages but i will search for them. Thanks for the info.
     
  20. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Cool, also you can write your own script. What's cool about those packages though is that the same code will work for touchscreen and mouse input (on the PC/Mac).
     
  21. Fahrettin

    Fahrettin

    Joined:
    Mar 10, 2014
    Posts:
    81
    I am hobbyist. I searched some topics for writing my own code yesterday. No chance at this moment. I try to learn but always stay at basics :D
     
  22. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    There's now a new forum for Core GameKit (and Master Audio) support, located here: http://darktonic.freeforums.net/. Please ask questions there instead of on this thread so that the next person who wonders the same thing might be able to find the answer easily.

    The thing is, quite annoyingly, the new forum doesn't email me whenever a new thread is posted (and I tried 3 other free forums - none of them have the option), so I will be checking there every evening. But of course Unity forums to email me immediately. So for best response time, please post your question in the new forum, then put a link here in this thread. Sorry about the runaround, I hope we can find a better way later on. This thread is much too large to serve as a support thread alone.
     
  23. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Hi

    I would like to set up levels and waves as per the Synchro Spawners, but instead of it spawned automatically (based on time) I would like to have it triggered as a Triggered Spawner - hope this makes sense.

    When I looked at the Triggered Spawner docs it says that ignores all the global wave/level settings, so I was wondering if there was any way of combining the two to get the best of both worlds? and what you might recommend as the best approach here?

    Essentially I am trying to do an endless driving game so I would like control over the distance at which prefabs are spawned (hence the trigger), but I would also like the wave/level/prefab control (all the good stuff from Synchro Spawners) so it can tell me when the level/wave finishes.

    Is this possible? If so what would you recommend as the best way forward here?


    cheers,

    Nalin



    BTW I tried registering on your forums, but it seemed to have no button to allow me to create a thread :(
     
  24. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    There is a create thread button, it just doesn't look like a button, more like a link, in the upper right. It says "Create Thread". I had to look hard for it myself :)

    Triggered spawners happen from events, not things you set up globally. Anyway, one thing you might try is to use some "endless" Syncro spawners to spawn prefabs that are Triggered spawners themselves, spawn one every X seconds or whatever. The triggered spawners can then have visible / trigger / collision events to do their own things.

    However, Syncro spawners stay in one spot, so you will probably need to add some sort of follow-player script to them so they keep up with the player or they'd be spawning things offscreen.
     
  25. puzzlekings

    puzzlekings

    Joined:
    Sep 6, 2012
    Posts:
    404
    Thanks Brian

    Just wondered whether it might be possible to extend the code such that the Synchro Spawner spawns when it receives an event of some kind?

    ... or maybe you could an suggest how to modify / extend an API call somewhere?

    cheers

    Nalin
     
  26. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    No, Syncro spawners do not work like that and will never work like that (goes against what they are for).

    If you want to control when things spawn, use the Code-Triggered Event 1 2 in a Triggered Spawner.
     
  27. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Core GameKit V3.2.1.4 will be live in 5 minutes. Changelog:

    • Added ClickToKillOrDamage script for mouse clicking (or finger tapping) to kill or damage Killables.
    • Changed example scene #4 to have no player. You click to damage the enemies.
    • Added "Wave Completion %" field to waves in Syncro Spawners that are during an Elimination Global wave. Defaults to 100. You can lower this to make a wave complete at X% destroyed so the wave can repeat or end.
     
  28. Fahrettin

    Fahrettin

    Joined:
    Mar 10, 2014
    Posts:
    81
    Jerotas Thanks for this update. I asked you too much about this :D
     
  29. gshape

    gshape

    Joined:
    Aug 8, 2012
    Posts:
    104
    Thanks a lot for this update Jerotas! :D
     
  30. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Hi Jerotas,

    I was wondering is there a way to despawn object via code? I am using 3.0 (didnt upgrade cause dont want to lose waves configuration 1/2 of game is done).

    Thanks in advance :)
     
  31. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Yes:

    Code (csharp):
    1. SpawnUtility.Despawn(Transform trans);
    Which version are you thinking will make you lose config? Upgrading to v3.0 is the big one that makes you lose data.
     
  32. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Thanks for answer.


    I have 3.0 now and I am afraid to go higher :)

    Also Jerotas, I have a problem with pooling. When I use triggered spawner on projectiles after some time there seems to be a conflict with the rotation of objects - i get funny results. I spawn for example 2 projectiles chose use custom rotation, set one rotation -15 and ofset to + 30 and after some time(fire multiple times) projectiles lose correct roration (i guess they are being spawnerd again after desppawn and they keep roation from previous spawn). Any solution for that?
     
    Last edited: Apr 22, 2014
  33. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You can read the release notes for the versions after 3.0 on page 1 of this thread. If there's not any certain breaking changes that worry you, go ahead and upgrade. First, make a separate prefab out of your LevelSettings prefab though to break the connection with the one in the Core GameKit folder.

    For your custom rotation, you are correct that objects keep their state from the previous despawn when they respawn. That's how all pooling solutions work and it is unavoidable by the nature of how pooling works. However, if you need to add some code into the OnSpawned event for initialization or state reset that runs every time it is spawned, you can do that (see the readme section under Pool Boss). But I don't see why the custom rotation would stop working since I believe that's absolute rotation, not relative.
     
  34. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    The problem was velocity,

    using UnityEngine;
    using System.Collections;

    public class test : MonoBehaviour {

    void OnSpawned() {

    rigidbody.velocity = new Vector3(0,0,0);
    }
    }

    Helped :)
     
  35. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Ah, cool!
     
  36. kathode

    kathode

    Joined:
    Jan 15, 2013
    Posts:
    63
    Updated through Unity from 3.2.1.1 to 3.2.1.4. Now when I select the LevelWaveSettings gameobject or any child, I get a warning spewed into the log every frame - "Logo texture missing
    UnityEngine.Debug:Log(Object)
    DTInspectorUtility:DrawTexture(Texture) (at Assets/DarkTonic/CoreGameKit/Editor/Helpers/DTInspectorUtility.cs:84)
    LevelSettingsInspector:OnInspectorGUI() (at Assets/DarkTonic/CoreGameKit/Editor/Level/LevelSettingsInspector.cs:21)
    UnityEditor.DockArea:OnGUI()"

    The Core GameKit logo in the inspector panel does indeed not show up any more. For the moment I'm commenting out that debug log because it makes the console unusable. Any idea how to fix or what I might have done wrong?
     
  37. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You'll need to delete the textures and then download the package again from the store, you have them in a different folder. I think /Assets/Core GameKit/Sources?

    It's a problem with the importer, it will keep the items in their wrong folder instead of adding them in the right folder.
     
  38. kathode

    kathode

    Joined:
    Jan 15, 2013
    Posts:
    63
    Edit: Ah, see the reply above, thanks!

    Yep verified. I deleted /Sources/Textures.meta and /Sources/Textures, reimported, and all seems to be well.
     
    Last edited: Apr 22, 2014
  39. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    As I suspected. Carry on!
     
  40. kathode

    kathode

    Joined:
    Jan 15, 2013
    Posts:
    63
  41. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    Hi Jerots, how to call this function via playmaker(have problem with passsing Transform trans)?Also what script needs to be attached to prefab?

    thanks
     
  42. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    If you're using Playmaker, you don't type the code, you use the CoreGameKitDespawn Playmaker Custom Action instead. It's not necessary to have any script on the object.
     
  43. ChrisMaster

    ChrisMaster

    Joined:
    Dec 27, 2013
    Posts:
    87
    lol :) didnt see that coming, thanks :)
    works like a charm :)
     
    Last edited: Apr 23, 2014
  44. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    It should be, but it's slightly tricky. You'll need to set up the timed wave to repeat so that the items are tracked (so it will know when all items are despawned). Then you have to use a Syncro Spawner Listener. Add some code to do: LevelSettings.EndWave() into the WaveRepeat method of the Listener. That should do it. I've replied in the forum too.

    I'll add an item to the to do list to make a way to do this without writing any code.
     
    Last edited: Apr 23, 2014
  45. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Thread title changed for new product name (Core GameKit)!
     
  46. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    Hello, two question about this, can we keep managing spawn event and variables by script? is it extensible?

    Have you tested to spawn and sync on network you pooled objects, do you have an example to provide if yes?
     
  47. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    You can choose to not use the spawner scripts and spawn things yourself from the included pooling system Pool Boss.
    This product has nothing to do with network anything.
     
  48. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    got the same answer from poolmanager, but if people want to use it in a multiplayer game then it require few changes or "method".

    using pooling in network game is as much interesting as any other games

    every networks frameworks: unity networking photon tnet etc, all have their instantiate/destroy object. and it would be interesting in a networking game case( bet i am not the only one which add pooling on this kind of game). to be able to add to a pool object loaded first with network functions like copy a list.
     
    Last edited: May 5, 2014
  49. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,572
    Really? What changes would it need? It seems like it would work fine as is, to me.
     
  50. Tiny-Tree

    Tiny-Tree

    Joined:
    Dec 26, 2012
    Posts:
    1,315
    well simply first create the game objects in a list with network instantiate function.

    and if we could be able to create a pool from a list at runtime, that would work.