Page 1 of 1

Poll on Spawner.cs

Posted: Sat Feb 16, 2019 4:33 pm
by GorkaGames
Hi,

Spawner.cs doesn't pool the instantiate GameOgjects, does it?

I'm trying to add the Opsive Pool system (see here:)
https://opsive.com/support/documentatio ... ject-pool/

But I can't add "using Opsive.UltimateCharacterController.Game;" as Visual Studio says Opsive Namespace was nor found.

Any ideas how can I procedure? I just one to change ObjectPool.Instantiate instead of Instantiate

Thanks.

Re: Poll on Spawner.cs

Posted: Sat Feb 16, 2019 5:52 pm
by Tony Li
Hi,

The methods in the Spawner class are virtual so you can override them to use a pooling system. However, there's a patch that makes it even easier by isolating the Instantiate and Destroy calls into separate virtual methods:

Code: Select all

        /// <summary>
        /// Returns an instance of a prefab. Override this method if you want to
        /// use a pooling system instead of Instantiate.
        /// </summary>
        protected virtual GameObject InstantiateEntity(GameObject prefab)
        {
            return Instantiate<GameObject>(prefab);
        }

        /// <summary>
        /// Destroys an instance of a prefab. Override this method if you want to
        /// use a pooling system to return the instance to the pool.
        /// </summary>
        protected virtual void DestroyEntity(GameObject go)
        {
            Destroy(go);
        }
Just create a subclass of Spawner that overrides these two methods.

Here is a link to the patch: QM_SpawnerPatch_2019-02-15.unitypackage

Re: Poll on Spawner.cs

Posted: Sat Feb 16, 2019 7:10 pm
by GorkaGames
Thanks very much!!