-1

I am Unity beginner and trying to activate a GameObject which I have referenced from the inspector and deactivate it after 3 seconds(with the help of Coroutine) and in the scene. I am not destroying the GameObject on which the Coroutine is attached to. Have spent so much time but still not able to figure out what's happening. When I replace the Coroutine with the simple void method it does not throws any exception but I have to use the Coroutine for the behavior I want.

[1]This is the code

[This is the exception]

enter image description here

  • When you paste code, paste text, not a picture. – aybe Aug 16 '21 at 19:53
  • I Think Dude, mostly null reference exception will come only when our game object is not assigned references. first, check this thing. in your inspector. – Chandan Aug 16 '21 at 19:58
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – BugFinder Aug 16 '21 at 21:03
  • @BugFinder Thank you for answering but sadly no that does not help. – The Noobest Guy Aug 17 '21 at 03:57
  • Well it shoukd you need to debug to work out what is null. It wont be telling lies :( – BugFinder Aug 17 '21 at 09:28
  • If it works with void, you can define your method 'private async void ShowError()' and instead using 'waitForSeconds' use await 'Task.Delay(TimeSpan.FromSeconds(3))'. (Search for async/await for more information) However, I cannot tell why coroutine raise an exception. – Soroush Hosseinpour Aug 18 '21 at 17:21

1 Answers1

0

I Think Dude,

mostly null reference exception will come only when our game object is not assigned references.

first, check this thing. in your inspector.

Like this->

Look at that

Chandan
  • 283
  • 2
  • 6
  • First of all Thank you for answering. Yes I have double checked it, everything is referenced properly. – The Noobest Guy Aug 17 '21 at 03:46
  • As you can see I have edited my question and added the image of the component where the coroutine resides. I am neither deactivating it nor destroying it but still at the point where the coroutine has to run, it throws the null reference exception. – The Noobest Guy Aug 17 '21 at 04:02