Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

38sec startup time SplashScreen Loading.LockPersistentManager on Standalone & Android after Upgrade

Discussion in 'General Discussion' started by OscarSalandin, Dec 4, 2022.

  1. OscarSalandin

    OscarSalandin

    Joined:
    Oct 28, 2015
    Posts:
    4
    Since upgrading my project from Unity 2019.3.0f6 to 2021.3.15f1, I now have a 41 second startup load time on my app, making it infeasible to use. On 2019 it was working well with a short startup.

    Does anyone know why this is happening and how I can fix it?

    The splash screen does not actually render on the screen, it just shows black on Android and on Windows it says (Not Responding) in the header for 41 seconds.

    The screen is black and I thought it had crashed, until I let it go for a while by accident. and saw the app eventually load and function normally.

    This only happens on builds, not in the editor. It happens on both Android and Windows Standalone builds.

    I have auto-connected the profiler when building and am finding that the CPU time is spent on SplashScreenRender > SplashScreenRenderForeground > Loading.ReadObject > Loading.LockPersistentManager (see screenshot below)

    The File Access module on the profiler isn't showing any large times, so I don't think it is about slow file access.

    Any help would be greatly appreciated!

    Unity SplashScreenRender slow startup.png
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,511
    This may or may not be related: https://forum.unity.com/threads/how-to-reduce-enter-play-mode-time.484279/#post-3155183

    Try adding an empty scene as the first scene and do nothing in it but keep the other scenes in the build, just to test if this empty scene comes up quickly. If it does, try loading the scene that was previously loaded as the first scene with a script you add to the empty scene, but be sure to call LoadScene in Update(). You cannot load scene's in Awake/Start/OnEnable right after a scene was loaded if I remember correctly.
     
  3. OscarSalandin

    OscarSalandin

    Joined:
    Oct 28, 2015
    Posts:
    4
    Fixed it. Recursive Serialization was the problem. Not sure why this is different to 2019.

    I had class A with a public field for class B that had a public field for class A, so the serialization goes on forever.

    This was fixed by making the fields use [NonSerialized] attribute.

    Unity did give me the error on editor startup but I missed it the first time:
    “Recursive Serialization is not supported. You can't dereference a PPtr while loading. (Constructors of C# classes may not load objects either. See stacktrace.)”

    Thanks for the help, @CodeSmile. It's typical that after a couple months not being able to fix it, then posting, it's solved 5 mins later!