Spawner script bug? (v3.0 release)

Help, support and information for our Pro Pooling Unity Asset
Post Reply
User avatar
nerd114
Posts: 2
Joined: Mon Apr 09, 2018 9:21 pm

Spawner script bug? (v3.0 release)

Post by nerd114 » Tue Apr 10, 2018 2:35 am

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 2134 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!

mahewitt
Site Admin
Posts: 252
Joined: Thu May 05, 2016 8:06 pm

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

Post by mahewitt » Tue Apr 10, 2018 8:49 pm

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

User avatar
nerd114
Posts: 2
Joined: Mon Apr 09, 2018 9:21 pm

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

Post by nerd114 » Wed Apr 11, 2018 1:07 am

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!

Post Reply