Object Pooling with Particles

So I’m trying to use object pools for the first time. I have two pools (Object A = projectile, Object B = trails).

I’m trying to spawn A and B simultaneously and parent B to A. I’ve gotten A to spawn just fine, but for some reason whenever I try to spawn B, I keep getting this error:

Here is the code snippet:

    ObjectPooler2 objectPooler;
    GameObject trailParticle;

  public void OnObjectSpawn()
    {
        spawnLocation = transform.position;

        trailParticle = objectPooler.SpawnFromPool("Player_BasicParticle", transform.position, Quaternion.identity);
        trailParticle.transform.SetParent(gameObject.transform);
    }

I want to parent B to A and then somehow stop the trails from playing once it collides with something. My previous method used Instantiate, and then unparent, and then letting the trails play themselves out. But I was hoping that object pooling would improve performance. Thoughts?

Most likely either objectPooler is null or objectPooler.SpawnFromPool is returning null (I assume line 8 or 9 in your snippet is line 34 in your script?)

How are you assigning the value of objectPooler?
Did you write the object pooler script yourself?

Oh! So it turned out I forgot to add this in the OnObjectSpawn: objectPooler = ObjectPooler2.Instance;

That fixed it. Thanks!

The Object Pool script was from this Brackeys video

An ObjectPooler2 class name implies the existence of another ObjectPooler class.
If you need multiple object pools, the singleton pattern is not one you’d want to use here.

Rather than needing to make ObjectPooler3/4/5/6... classes, it would be better to remove “Instance” and just reference an ObjectPooler as any other MonoBehavior component or C# object instance.