Update only called once in Monobehaviour

I have procedural generated level that spawns prefabs with monobehaviours that have some timed actions. These prefabs work fine when dropped into the scene directly. However when instantiated by the level generator, the update method is only called once which means the timed actions do not update.

I have checked the scene while the game is running to make sure the game objects and components are all activated, and they are, so it should work.

Any ideas what can cause the Update method to stop being called?

How did you test that the Update method is only run once? Are there any exceptions? Unity runs the Update functions of alive and active gameobjects once per frame. If they are not run, then the object would have to be destroyed, set inactive, or the execution of the method would have to be prevented by an occuring error.

1 Like

I added a print statement at the top of the Update method of my monobehaviour before any other code. I see the statement appear only once per prefab instance. Also, there’s a public variable that holds the timer value which, when it’s working can be seen to decrease in value, but in this case it stays at the same value.

Also I checked the instantiated prefabs in the scene while the game is running, and they’re all active.

Maybe there’s a silent error?

Are you sure it’s actually only logging once? Maybe Unity’s console window is automatically collapsing duplicated messages. You can turn this feature off by toggling “Collapse” on the console:

Another possibility: Are you manually calling the Update method somewhere? It’s possible you have the method signature wrong but it’s getting called once manually. Sharing your script would be helpful.

2 Likes