# Particle system prefab not instantiated

I am trying to instantiate my fire particle system during runtime like this:

GameObject fire, firePrefab;

void Start()
{
...
firePrefab = Resources.Load("FirePrefab") as GameObject;
}

void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.V))
{
fire = Instantiate(firePrefab, transform.GetChild(3).position, transform.GetChild(3).rotation);
Destroy(fire, 5.0f);
}
}


My FirePrefab is just a regular particle system, and the model the above script is attached to looks like this:

Model

Default

Camera

DroneFire

However, my fire prefab isn't instantiated anywhere when I run the game.

• Any errors? Did you check if fireprefab is actually loaded and not null? – ElDuderino Sep 10 '17 at 23:39

## 1 Answer

GetChild is zero-based. to get the first object, "Default", you would call GetChild(0). In your case, to get "DroneFire", you should call GetChild(2), not GetChild(3) which will throw an exception before the instantiation can occur, because no such child exists. This exception should be fairly obvious in the console output. I would recommend looking in the console regularly when things don't work to find where things are failing.

fire = Instantiate(firePrefab, transform.GetChild(2).position, transform.GetChild(2).rotation)


As a side note, polling for input should generally not be done in FixedUpdate. Change to Update instead.