Update method not being called after switching scenes

Update method not being called after switching scenes
0.0 0


I have two scenes in my app. In the second scene in init() method I have this->scheduleUpdate();. After switching the scene from first to second update method in the second scene works correctly but if I switch back to the first scene and then again switch to the second scene then update in second scene is not being called. Is this normal? Should I call some additional method when I’m switching to second scene to make update() work again?

I moved scheduleUpdate(); from my init() method of second scene to onEnter() and it seems to be working fine however it feels more like a workaround than a proper solution.


I have the same issue. I don’t know this is bug or not. Can anyone explain?


Yes this is normal, when a new cocos2d::Scene is made active by the Director it’s cleanup() method is called, which unschedules all functions associated with it.

You shouldn’t really be scheduling an update in init() as the scene will begin updating before it becomes active.

onEnter() is the correct place, and you should unschedule the update in onExit(). When a Scene becomes active the Director calls it’s onEnter(), and subsequently onExit() when the scene becomes inactive.

Another solution/approach would be to always destroy your scenes when you switch. Building a new second scene each time will call scheduleUpdate() each time. This is usually recommended in most cases anyway as it minimises memory overhead.

Hope this helps