Forum rules - please read before posting.

Abnormally long switch scene loading time in build

edited January 13 in Technical Q&A

Hi, encounter a scene loading problem in Windows build (I don't have chances to try other platforms yet). I am using Unity 2018.1.4f2 and AC1.69.4.

When doing a scene switch (using Actiona List) to an empty AC scene, it takes 30s to load, 60s on a weaker computer. If I use the same action to switch to an empty scene (without AC GameEngine), it can load in less than a second.

In the Editor, the AC scene can be loaded in less than a second too.

Preloading scene doesn't seem to help (I have Load scenes asynchrously checked, and not using loading screen).

What would be causing this?

«1

Comments

  • I just realized that... if I switch scene by calling the script:

    AC.SceneInfo mySceneInfo = new AC.SceneInfo(sceneName);
    AC.KickStarter.sceneChanger.ChangeScene(mySceneInfo, false);

    The long loading time is gone. It is a work around but how would this happen?

  • Is this for all scenes, or just when moving from one specific scene to another specific scene? If you switch from the first scene to a different one, or switch to the second scene from a different first, is there any difference?

    The second parameter in ChangeScene determines whether or not the scene's current state is saved or not. What does the first scene contain in terms of Remember scripts?

    Hard to tell exactly what would cause this, though. See if you can get Deep Profile results from the build:

  • I think "The second parameter in ChangeScene determines whether or not the scene's current state is saved or not" is the issue. If I set it to true, then the delay happens. In the first scene, there are 25 NPCs and they have the Remember Transform and Remember NPC components, which on second thought I think those are not needed. But would this amount normally cause the delay?

    However, when an autosave happens in the scene, such delay doesn't exist. So I wonder why the scene saving would cause the delay during scene switch but not during autosave.

    About Deep Profiling, I dunno why my Deep Profile button is always grey, even when I follow the above video.

  • Btw, in this case it would be helpful if the scene change action has an option of choosing whether to save the scene data, although I am not sure how often others will find it useful.

  • That the autosave doesn't have such a delay does indeed make it hard to see why this would occur - all the more reason to see the results of profiling.

    That the button is grey is a Unity issue - a search of the Unity forums shows discussions on this:

    https://forum.unity.com/threads/solved-deep-profile-disabled-when-profiling-a-standalone-client.535191/

  • I identified the problem: It is when the scene has no Player object, and AC has to generate the Player according to the Player Prefab in Settings.

    When this happens, the profiler shows 2 items taking up the time:
    1. https://imgur.com/a/13vBpFL
    2. Second one is weird. It is a shader that I can't see I am using and takes 40s to load. If I delete the shader from the project, another process will show up that also takes 40s to load...

    I can work around this by putting the player at every scene. But to take care when the player has an animator change during the scene, extra scripting is needed to save the animator before scene change and load it after scene change.

    Have you ever encountered cases like that? Is it just my project problem?

  • So the scene you're loading from has a local Player prefab that overrides the default?

    The second item doesn't sound AC-related, so I can't offer much on that. The first, however, is related to the restoration of player asset data - i.e. walk sounds, portrait texture, etc.

    Such files are placed in Resources folders so that they can be accessed in builds. If you have many files in Resources folders, searching for these files can take time. To get around this, you can create special subfolders that are used to house these assets.

    See the Manual's "Performance and optimisation" chapter - specifically the "Use Resources subfolders" section.

  • "So the scene you're loading from has a local Player prefab that overrides the default?"

    Previously, both the scene to load from and the scene to load to has no local Player in the hierchy. It had long loading time.

    Now when I put a local Player in the hierchy in each scene, the long delay is gone.
    And when I do that, the second issue of the shader process is also gone.

    With the Player in the scene hierchy, does it mean the player asset data is not needed to be searched?

  • edited January 16

    For special subfolders, like SaveableData/Animations, does it have to be under Resources or it could be anywhere?

    I think this might be the cause for the delay, my Resources folder is quite big, and there are a few Resoures folders in other plugins.

    Can I only make certain SaveableData folder like only Audio but not any others?

  • With the Player in the scene hierchy, does it mean the player asset data is not needed to be searched?

    Searching is something it should do - so as to restore any saved data related to them. This should only occur when re-entering the scene or using a Player that's been previously played as.

    For special subfolders, like SaveableData/Animations, does it have to be under Resources or it could be anywhere?

    They need to be direct subdirectories within Resources. The optimisation works by limiting the searching of Resources to specific subdirectories.

    Can I only make certain SaveableData folder like only Audio but not any others?

    I'd recommend making all of them, but they are independent - so each one only improves the load times of that particular asset type. As the Manual covers, though, you'll need to make a "dummy" asset in each folder if you have no assets to search for. For example, place a new Material in the SaveableData/Material directory.

  • I'd recommend making all of them, but they are independent

    I understand, but a difficult is that when multiple other plugins are used, and when the project is getting big, I am afraid to miss some assets from other Resources folders...

    Btw, can there be subfolders inside the Special Folders?

  • I understand, but a difficult is that when multiple other plugins are used, and when the project is getting big, I am afraid to miss some assets from other Resources folders...

    Sorry, could you elaborate on this? The SaveableData feature shouldn't affect any other plugins or non-AC searches of Resources files. Only files that AC is looking for need to be in them.

    Btw, can there be subfolders inside the Special Folders?

    I'm not sure, actually. Likely not - see Unity's docs on the operation here.

  • Sorry, could you elaborate on this? The SaveableData feature shouldn't affect any other plugins or non-AC searches of Resources files. Only files that AC is looking for need to be in them.

    Because in the manual it says
    "Note that once these subfolders exist,
    however, all such assets must be placed in them correctly for AC to be able to find them."

    I am afraid I may miss some assets used by other plugins in this way. Actually maybe I misunderstood how these folders works, what kind of assets would be affected by such folder arrangement?

  • edited January 19

    Another weird thing is, although now the loading time of switching scene is short, if the Player goes back to a previously loaded scene, the loading time is long again.. Would that be related to the Player assets loading as well?

    Otherwise, would there be a way to clean the data of the previous scene, and load it like a new scene even on the secnond entry?

    Thanks for helping me again.

  • Note that once these subfolders exist, however, all such assets must be placed in them correctly for AC to be able to find them."

    This only applies to assets that AC requires access to. Unrelated assets, from other plugins, are not affected by this.

    although now the loading time of switching scene is short, if the Player goes back to a previously loaded scene, the loading time is long again.. Would that be related to the Player assets loading as well?

    What does a Deep Profile scan reveal?

  • This only applies to assets that AC requires access to. Unrelated assets, from other plugins, are not affected by this.

    Does that include the assets that got drag-and-drop into actionlists? Or only assets loaded by script, loading and scene changes?

    What does a Deep Profile scan reveal?

    A shader that I can't see I am using, and if I delete the shader from the project, another process will show up that also takes 40s to load... So I think there is some process that I cannot see in the profiler. I will try to dig deeper on this. But consider that the "first-time enter scene" loading time is gone when I put a local Player in the scenes, I think the re-entering scene delay is exactly the same as what happens if I don't put the local Player in the scenes.

  • edited January 20

    Does that include the assets that got drag-and-drop into actionlists? Or only assets loaded by script, loading and scene changes?

    And in a more general context, base on what criterias should I judge whether the asset has to be placed in the special folders?

  • See the Manual's "Saving asset references" chapter. If a change is made to e.g. a character's walk sound, or an object's material, through Actions - then that asset will require placement in such a folder to be saved.

    The current list of scenarios whereby asset loading occurs is as follows:

    • An ActionList Asset, if paused when saving
    • A Sound's AudioClip, if playing when saving
    • All AnimationClips referenced by characters that use "Legacy" animation
    • Character walk/run sounds
    • Character portrait textures
    • Timelines, if a RememberTimeline component has Save Timeline asset? checked
    • AnimatorControllers, if a RememberAnimator component has Save change in controller? checked
    • Materials, when a RememberMaterial component is used
    • VideoClip assets, when a RememberVideoPlayer component has Save clip asset? checked

    In the specific case of character assets: these are loaded in even if they weren't changed. I am, however, looking to see if this requirement can be lifted.

  • Thanks. For Animator Controllers, do I also put them in the Animations special folder?

  • Actually in the case of Animator Controllers - these are left out of the SaveableData process. I shall address this.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!