Forum rules - please read before posting.

Loading Optimalisation

Hi,

I've run into a problem with long scene loading times. I'm doing 2D game and I'm aware of the fact that these games are resources heavy. Anyway the reason why I'm posting here is that when I disbale AC's GameEngine object the scene switch is basically instant (going from AC scene to scene with AC turned off), just a few ms of a black screen. The resources are still loaded including characters and their animations. With AC active on the other hand it can easily take up to 10s or even more.

My question is what is the process that's happening when a scene is being loaded?

I read the manual's section on optimalisation but here are some of my thoughts on things not being mentioned there.

Menus
Unless I'm mistaken all the menus are being loaded on a scene load. I already have 18 menus. The problem with them is that some of the menus are needed only during a specific part of the game (but not in a single scene only) and then they will not be used ever again but still being loaded forever. I'm thinking whether there's a way to unassign a menu to be loaded. To remove it when not needed anymore.

Global Variables
How many is too much? As everything is basically connected it's quite often that thing from one scene will affect another thing from a different scene. Global variables are then required. Are they being all loaded on a scene load? Again at some point of the game most of the global variables will never be needed again.

AudioFiles
I understand that AssetBundles are more optimized when Auto-name speech audio files? is checked. But is it still the case when everything is manually assigned?

Comments

  • In the case of Menus and Global Variables - these are game-wide entities, and so are not effected by a scene change. They are initialised when AC begins, and when loading a save game file.

    You can, of course, quickly test their effect by swapping back to e.g. the 2D Demo's Menu / Variables Managers - though the game won't run correctly, you should at least be able to test a scene change.

    In the case of audio files - Asset Bundles are more performant than manually assigning them, because Unity loads in assigned references even when not being used.

    The use of Addressables is another option - I've written an integration script here.

    I've been working on improving the startup / scene-switching processes as part of the v1.71 update - PM me if you'd like to be involved in testing. However, the best way to learn what's really causing the long load times is to use the Profiler. What does this reveal in your case?

    Though you've likely already encountered it in the Manual, one big thing to keep in mind so far as 2D games go is that of the number of animations present in your Player's animator. If you have many "one off" animations that are typically used in only very specific scenes, it's worth considering the reliance on Timeline sequences for them instead - to reduce the number of clips your Player character has. Or alternatively, relying on "local" Player characters for scenes that require lots of custom animation.

  • Thanks for the info. Gives me a better picture on how to be handling things.

    Had to look into the profiler as I haven't use it yet. Well, there's a strange thing happening. I created a loading screen with a progress bar to be used in-between scenes.
    It takes just a few frames to get the bar completed and then it just freezes. The profiler is not doing anything at all. The loading bar is completed.
    And this is the part where it just loads for a very long time. Again happening only with AC present in the scene. Any idea how to proceed?

  • Update: I can let AC being on and switch scenes with Unity's scene manager and it's still quick. There's something happening during that switch that makes the game frozen for a bit.

  • Sure - if you opt to switch scenes using Unity's scene management, then AC isn't able to run the processes it needs to. The largest of which is to save the state of the closing scene, so that it can be restored to this way upon re-entering.

    Be sure to enable "Deep Profile" when using the Profiler so that you can drill down further - but please consider my offer of testing the upcoming release, as it deals with this area.

  • I wonder if you have an idea based on your experience how a well optimised and managed 2D game using AC can have a long switch loading times. What is realistic to expect?

  • After testing 1.71 I can tell that it does seem to be sometimes around 1s quicker. Though the change is subtle and thus it's not easy to tell as the loading time is always a bit different.

    The profiler is showing bunch of data I'm not sure what they are. This switch took around 9s. What's happening during PlayerLoop?

    https://i.imgur.com/JFaXxjI.png

    What concerns me is that deleting basically everything from the scene and almost also all animations from player's controller didn't have any impact on the switch speed at all.

  • Certainly for a "basic" 2D game, I'd expect it should be less than 10 seconds.

    When using the Profiler, switch to Hierarchy mode - that's a lot easier to guage where issues are happening from.

    The "PlayerLoop" is a Unity process - the standard Update loop - and not something specific to AC.

    What concerns me is that deleting basically everything from the scene and almost also all animations from player's controller didn't have any impact on the switch speed at all.

    And what if the same is done to the preceding scene?

    I can only talk in vague / general terms without knowing the actual situation. If you can create a duplicate project with just a pair of test scenes - yet still demonstrates slow load times in the Unity Editor - you can send the whole thing to me and I'll take a look.

  • And what if the same is done to the preceding scene?

    Aye, I deleted it in both. Forgot to mention that.

    Alright. Thanks. I'll send you my notes regarding to v1.71 plus a stripped project via PM.

  • Just a note to anyone reading this that might have a similiar issue. I had all my assets in a resource folder. AC goes through this folder looking for assets that might need to be loaded in.

  • edited March 2023

    Hi, sorry to jump on this thread, but I have a very similar issue.

    Switching scenes causes the game to lag and sometimes crash.
    Through trial and error, this is what I found out:

    • Only happens on MacOS builds, not PC
    • Only happens when creating builds at higher resolutions (1920x1080 is fine, native display resolution at 3456 x 2234 is not)
    • No issues if I build the scenes independently and play them
    • However, if I build a single scene and reload it, the same issue happens.

    Here are two frames of my profiler log

    (the calm before the storm)
    https://imgur.com/ZGplW2c

    (all hell breaks loose)
    https://imgur.com/xXrcC8l

    Any pointers as to what I could look at to improve the scene switching? Note that I'm still on AC 1.68.0

  • Welcome back, @fffff.

    What's your Unity version? If it's platform-dependent, it may be a Unity issue.

    The profiler spike doesn't look to reference AC - instead it appears to reference Post Process Layer. Try expanding the terms with the highest "GC Alloc" and "Time ms" values - starting from "PostProcessLayer.InitBundles()" in the second screenshot.

  • Thanks Chris, still offering amazing support as always!

    Did a bit more investigting this morning, posting the results here in case anyone is in the same boat.

    Scene reloading works without glitches with the default AC MainCamera so this wasn't an AC issue.

    However, my main camera relies heavily on post-processing effects and the culprit was one of the scripts that wasn't destroyed properly.

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.