Setting up a helper method to assign a gameObject

I’m trying to set up a helper method to make it easy to setup objects pools.

This works:

    private void initAsteroidPool()
    {
        asteroidPool = new GameObject(ASTEROIDS + POOL);
        asteroidObj = LoadGameObjectResource(AsteroidPrefabName);
        asteroids = CreateObjectPool(ASTEROIDS, asteroidObj);
        asteroids.LateStart(asteroidPool);
    }

    GameObject LoadGameObjectResource(string resource)
    {
        return (GameObject)Resources.Load(System.String.Format("{0}/{1}", PrefabsDirectory, resource));
    }

But I end up doing to for every object to pool. Here is my attempt at creating a helper method that I can just throw in parameters to get it to create my object pool.

    private void initializeObjectPool(GameObject gameObjectPoolHolder, ObjectPool objectPool, string name, string prefabName, GameObject gameObjectToPool)
    {
        gameObjectPoolHolder = new GameObject(name + " " + POOL);
        gameObjectToPool= LoadGameObjectResource(prefabName);//Loads the prefab into the GameObject
        objectPool = CreateObjectPool(name, gameObjectToPool);
        objectPool.LateStart(bulletPool);
    }

What am I doing wrong?

I’m guessing

objectPool.LateStart(bulletPool);

should be:

objectPool.LateStart(gameObjectPoolHolder);

I needed to pass the parameters as references. It’s a bit tricky to understand but what’s happening in the new code is I’m passing THE reference instead of A reference to the method. This means that once the method has ended the changes stick.

initializeObjectPool(ref asteroidWarningsPool, ref  asteroidWarningObj, ref asteroidWarnings, ASTEROID_WARNINGS, AsteroidWarningPrefabName);

private void initializeObjectPool(ref GameObject gameObjectPoolHolder, ref GameObject gameObjectToPool, ref ObjectPool objectPool, string name, string prefabName)
{
    gameObjectPoolHolder = new GameObject(name + " " + POOL);
    gameObjectToPool = LoadGameObjectPrefab(prefabName);
    objectPool = CreateObjectPool(name, gameObjectToPool);
    objectPool.LateStart(gameObjectPoolHolder);
}