Page 1 of 1

Spawner script bug? (v3.0 release)

Posted: Tue Apr 10, 2018 2:35 am
by nerd114
Hi Mark,

I downloaded (and imported) the v3.0 release of Pro Pooling and just encounter a bug when scripting with the Spawner.

Here's a snippet of my Spawner script on my Start event.

Code: Select all

public class UvzGamePlay : Singleton<UvzGamePlay> {

    public GameObject gamePlane;
    Spawner spawner;

    // Replace Awake()
    protected override void GameSetup() {
        //Debug.Log ("Game Play setup");
    }

    // Use this for initialization
    void Start () {
    if (gamePlane != null) {
        spawner = gamePlane.GetComponent<Spawner> ();

        if (!string.IsNullOrEmpty (UvzPersistent.Instance.myPrefs.RawInventory)) {
	    spawner.StartSpawning ();
	}
    }
}
When I run the scene and call spawner.StartSpawning(), it gave me the error below; (Note: I added debugs on methods of SpawnOverTime class)
Spawn_error_when_not_initialized.PNG
Spawn_error_when_not_initialized.PNG (14.33 KiB) Viewed 2375 times

It seems the Start() method of SpawnOverTime is being called first so I added the spawner.SpawnOverTime.Initialise (spawner) before the spawner.StartSpawning() and it worked. (except that it calls the initialise twice);

Code: Select all

if (!string.IsNullOrEmpty (UvzPersistent.Instance.myPrefs.RawInventory)) {
    spawner.SpawnOverTime.Initialise (spawner);
    spawner.StartSpawning ();
}
Is this the correct way of doing the Spawner script?

Cheers!

Re: Spawner script bug? (v3.0 release)

Posted: Tue Apr 10, 2018 8:49 pm
by mahewitt
Hi,

Just trying to think why I put that method in Start() and not Awake().. I think it was to do with ensuring the pool was setup before using it...!

What you have should be fine, although you might want to just try increasing the script execution order of the Spawner component so it is guaranteed to be called first hopefully that might make it work without the extra call.

Regards,
Mark

Re: Spawner script bug? (v3.0 release)

Posted: Wed Apr 11, 2018 1:07 am
by nerd114
Hi Mark,

Thanks Mark for the quick response.

I'll try to put the spawner start call further down the execution path.

Will let you know if I encounter any more quirky stuffs.

Thanks for the support and the cool Unity assets! :D

Cheers!