Object reference not set to an instance of the object

Hello, I’m really stuck here and I appreciate your help.
I wrote the code just as it is said in the video, but i still get
"NullReferenceException : Object reference not set to an instance of the object." error.

if I only write this line it works just fine, the brick gets destroyed and white particles play

GameObject smokePuff = Instantiate(smoke, transform.position, Quaternion.identity) as GameObject;

I add this line, build in the mono and it gives no error, but on the console it still gives the error.
The bricks dont get destroyed and white particles play.

smokePuff.particleSystem.startColor = gameObject.GetComponent<SpriteRenderer>().color;

You need to format your code when you post it, you can also edit your initial post rather than adding repies etc.

Which version of Unity are you using?


See also;

I’m sorry. I solved the problem.
I had declared the smoke instance type of ParticleSystem instead of GameObject.

1 Like

No worries at all, the link / info was just for future reference.

Glad you have resolved the issue and can move forward again Bartu :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms