Poll on Spawner.cs

Announcements, support questions, and discussion for Quest Machine.
Post Reply
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Poll on Spawner.cs

Post 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.
User avatar
Tony Li
Posts: 22107
Joined: Thu Jul 18, 2013 1:27 pm

Re: Poll on Spawner.cs

Post 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
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Poll on Spawner.cs

Post by GorkaGames »

Thanks very much!!
Post Reply