Search code examples
unity-game-engineparallax

Does disabling graphics game objects prevent them from being affected by scripts?


I'm using frames (bounding boxes) to disable all game objects within an area when the player is not in that area. I want to know if parallax scripts will affect a disabled frame of objects. I don't want the parallax of background and foreground layers to be off when the player enters a new frame.

Slightly off-topic, but still relevant enough: I'm building the frames to be seemless transitions; is there a way to prevent parallax overlap at the transition point?


Solution

  • Scripts on disabled gameobjects do not recieve Update calls, as you've noticed. There are a few things you can do:

    • Not disable the entire gameobject when its outside the camera frame, instead only disable the renderer attached. This way your parralax script is still updated. Though its questionable if there are performance benefits to this, Unity does Frustrum culling by default.
    • Dont have individual parallax scripts, instead have one ParallaxManager in which you register all objects. This manager is never disabled, as an added benefit there is less overhead calling update.
    • Instead of update start some coroutine on another object, that isnt disabled. For example, in Parallax you can start a coroutine from the Camera gameobject. That way it keeps going, eventhough the parallax is disabled.
    • Try to calculate the right position in the OnEnable. That way you can still disable objects, and they appear at the right position when they are enabled again.