i have a generail script for projectiles , that has an update the moves it the projectile.
is there a way to disable this update for the script in another script.
i have a rocket and i not want the update to start until i require it
i have a generail script for projectiles , that has an update the moves it the projectile.
is there a way to disable this update for the script in another script.
i have a rocket and i not want the update to start until i require it
If you can get a reference to a particular script component, setting its enabled
flag to false
will stop calls to its Update()
function.
It’s also possible to disable an entire GameObject and its children by calling SetActiveRecursively(false)
on it.
This is just sort of an append to the answer above. Though it does appear to work, and the documentation states: “Enabled Behaviours are Updated, disabled Behaviours are not.” I found that this description for the behavior of the enabled flag is not complete.
In my own project, class inherits from both MonoBehaviour, and IPointerDownHandler, and I hoped to use the enabled flag to enable and disable the Update function’s execution. This way I could avoid having to make a call to Update every inactive frame just to make an if check and jump out. However, when the enable flag is set to false, the OnPointerDown method, and presumably others, are not called either.
I thought this could merit some review of the online documentation here, to provide a better description of which functions are not executed when a Behaviour is disabled. Though I’m not sure where I would post such a request.
I would also still like to find a more suitable method for providing the functionality I described above, if anyone has any information on how to do so.