Search Unity

Question Where's the documentation on Unity's default PlayerLoops?

Discussion in 'Documentation' started by Armageddon104, Jan 15, 2024.

  1. Armageddon104

    Armageddon104

    Joined:
    Sep 14, 2014
    Posts:
    23
    Documentation references:
    https://docs.unity3d.com/ScriptReference/LowLevel.PlayerLoopSystem.html
    https://docs.unity3d.com/ScriptReference/PlayerLoop.Initialization.AsyncUploadTimeSlicedUpdate.html

    I'm working with PlayerLoopSystems and the default Unity PlayerLoops have no documentation beyond: "A native engine system that the native player loop updates."

    When you call PlayerLoop.GetDefaultPlayerLoop() (or PlayerLoop.GetCurrentPlayerLoop() if you never overrode it) you get this list:

    TimeUpdate
    ->WaitForLastPresentationAndUpdateTime
    Initialization
    ->ProfilerStartFrame
    ->UpdateCameraMotionVectors
    ->DirectorSampleTime
    ->AsyncUploadTimeSlicedUpdate
    ->SynchronizeInputs
    ->SynchronizeState
    ->XREarlyUpdate
    EarlyUpdate
    ->PollPlayerConnection
    ->GpuTimestamp
    ->AnalyticsCoreStatsUpdate
    ->UnityWebRequestUpdate
    ->ExecuteMainThreadJobs
    ->ProcessMouseInWindow
    ->ClearIntermediateRenderers
    ->ClearLines
    ->PresentBeforeUpdate
    ->ResetFrameStatsAfterPresent
    ->UpdateAsyncReadbackManager
    ->UpdateStreamingManager
    ->UpdateTextureStreamingManager
    ->UpdatePreloading
    ->UpdateContentLoading
    ->RendererNotifyInvisible
    ->PlayerCleanupCachedData
    ->UpdateMainGameViewRect
    ->UpdateCanvasRectTransform
    ->XRUpdate
    ->UpdateInputManager
    ->ProcessRemoteInput
    ->ScriptRunDelayedStartupFrame
    ->UpdateKinect
    ->DeliverIosPlatformEvents
    ->ARCoreUpdate
    ->DispatchEventQueueEvents
    ->Physics2DEarlyUpdate
    ->PhysicsResetInterpolatedTransformPosition
    ->SpriteAtlasManagerUpdate
    ->PerformanceAnalyticsUpdate
    FixedUpdate
    ->ClearLines
    ->NewInputFixedUpdate
    ->DirectorFixedSampleTime
    ->AudioFixedUpdate
    ->ScriptRunBehaviourFixedUpdate
    ->DirectorFixedUpdate
    ->LegacyFixedAnimationUpdate
    ->XRFixedUpdate
    ->PhysicsFixedUpdate
    ->Physics2DFixedUpdate
    ->PhysicsClothFixedUpdate
    ->DirectorFixedUpdatePostPhysics
    ->ScriptRunDelayedFixedFrameRate
    PreUpdate
    ->PhysicsUpdate
    ->Physics2DUpdate
    ->PhysicsClothUpdate
    ->CheckTexFieldInput
    ->IMGUISendQueuedEvents
    ->NewInputUpdate
    ->InputForUIUpdate
    ->SendMouseEvents
    ->AIUpdate
    ->WindUpdate
    ->UpdateVideo
    Update
    ->ScriptRunBehaviourUpdate
    ->ScriptRunDelayedDynamicFrameRate
    ->ScriptRunDelayedTasks
    ->DirectorUpdate
    PreLateUpdate
    ->AIUpdatePostScript
    ->DirectorUpdateAnimationBegin
    ->LegacyAnimationUpdate
    ->DirectorUpdateAnimationEnd
    ->DirectorDeferredEvaluate
    ->AccessibilityUpdate
    ->UIElementsUpdatePanels
    ->EndGraphicsJobsAfterScriptUpdate
    ->ConstraintManagerUpdate
    ->ParticleSystemBeginUpdateAll
    ->Physics2DLateUpdate
    ->PhysicsLateUpdate
    ->ScriptRunBehaviourLateUpdate
    PostLateUpdate
    ->PlayerSendFrameStarted
    ->DirectorLateUpdate
    ->ScriptRunDelayedDynamicFrameRate
    ->PhysicsSkinnedClothBeginUpdate
    ->UpdateRectTransform
    ->PlayerUpdateCanvases
    ->UIElementsRepaintWorldPanels
    ->UpdateAudio
    ->VFXUpdate
    ->ParticleSystemEndUpdateAll
    ->EndGraphicsJobsAfterScriptLateUpdate
    ->UpdateCustomRenderTextures
    ->XRPostLateUpdate
    ->UpdateAllRenderers
    ->UpdateLightProbeProxyVolumes
    ->EnlightenRuntimeUpdate
    ->UpdateAllSkinnedMeshes
    ->ProcessWebSendMessages
    ->SortingGroupsUpdate
    ->UpdateVideoTextures
    ->UpdateVideo
    ->DirectorRenderImage
    ->PlayerEmitCanvasGeometry
    ->PlayerRenderUIEBatchModeOffscreen
    ->PhysicsSkinnedClothFinishUpdate
    ->FinishFrameRendering
    ->BatchModeUpdate
    ->PlayerSendFrameComplete
    ->UpdateCaptureScreenshot
    ->PresentAfterDraw
    ->ClearImmediateRenderers
    ->PlayerSendFramePostPresent
    ->UpdateResolution
    ->InputEndFrame
    ->TriggerEndOfFrameCallbacks
    ->GUIClearEvents
    ->ShaderHandleErrors
    ->ResetInputAxis
    ->ThreadedLoadingDebug
    ->ProfilerSynchronizeStats
    ->MemoryFrameMaintenance
    ->ExecuteGameCenterCallbacks
    ->XRPreEndFrame
    ->ProfilerEndFrame
    ->GraphicsWarmupPreloadedShaders
    ->ObjectDispatcherPostLateUpdate


    Furthermore in my testing, not a single PlayerLoopSystem has a loopConditionFunction except for FixedUpdate which the documentation says: "The loop condition for a native engine system. To get a valid value for this, you must copy it from one of the PlayerLoopSystems returned by PlayerLoop.GetDefaultPlayerLoop."
    I'm guessing this is just for delaying the FixedUpdate/physics?

    The top-level PlayerLoopSystems like EarlyUpdate, Initialization, Update, etc. are missing an updateFunction which the documentation says: "A native engine system. To get a valid value for this, you must copy it from one of the PlayerLoopSystems returned by PlayerLoop.GetDefaultPlayerLoop."
    This means it's impossible to replace Update or any other top-level system. So I've resorted to recreating the ones I need and then putting my own PlayerLoopSystems in the top-level subSystemList.

    But lastly we come to the really really big bad issue. Replacing the PlayerLoop to just this:

    TimeUpdate
    ->WaitForLastPresentationAndUpdateTime // I've determined this system is required for Time.deltaTime and etc. to be updated
    Update
    ->Tick // My custom one, input works 10% of the time upon entering Play Mode with calling InputSystem.Update(); here, I probably need to add back PollPlayerConnection and others to fix it

    runs perfectly fine in the editor, and crashes on build, with no errors. Now, obviously I know a lot more systems are required for Unity to function (I'm guessing lots of graphical ones like: ShaderHandleErrors, GraphicsWarmupPreloadedShaders, etc.). But I literally can't know what is necessary and what isn't unless I go through and test each and every subsystem and then build.
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 5, 2024
    Posts:
    466
    You aren't supposed to replace the loop but add to it and remove from it when you are done.
    You can find an example in my wrapper for this in my Playerloop package.

    Here is a concrete example.

    Also, please do not cross-post:
    https://forum.unity.com/threads/unity-community-code-of-conduct.743180/
     
    Last edited: Jan 15, 2024
    spiney199 likes this.
  3. Armageddon104

    Armageddon104

    Joined:
    Sep 14, 2014
    Posts:
    23
    Thank you for the example, this is pretty straightforward though. I don't see why I should have a bunch of unnecessary functions bloating my update loop when they could be easily omitted with a tiny bit of work. I do realize the API seems designed just to add to the existing systems though.

    Either way, this still seems like something that would benefit the community by being properly documented.

    Yes I mistakenly posted over there since I missed the Documentation section, that's my bad, I already reported it since these forums don't let you delete threads.