Enabling of script not calling Start()

Hey!

The Unity Documentation says that the Start() function is called when the script is enabled. In my game I would like to be able to disable this script and then when I re-enable it (multiple times), I would like the Start() function to be called again. Is this possible? Or am I misunderstanding the docs?

Thanks

I think start is only called when the script is first enabled (run) after that there are two functions
to enable:

void onEnable()

to disable

void onDisable()

these are called each time a script is enabled/disabled

1 Like

What i read from the docs is that it will only work once in a behaviours lifetime so Start() will only be called once and on reanabling it, it wont.

Start is only called once at the beginning of the behavior and is will not be initialized again unless you invoke it yourself or call it again. For what you want, I believe you want OnEnable and OnDisable.

Also note that OnEnabled is called after Start on initialization as well.

Initialize->Awake->Start->OnEnabled
Disable->OnDisabled
Enable->OnEnabled

1 Like

Thanks heaps! That’s exactly what I was after. I wasn’t aware that function existed. Thanks again!