Need guidance on best way to handle large number of animations

Hi guys,
I have about 100 animation clips in my project totaling about 60MB. In traditional Unity projects, I split these into addressables and load them when needed, keeping the file size small at all times. I could also have loaded assets from the Resources folder. Without the extra animations, my built project is about 11MB, and I was hoping to just download the assets when they are needed. Is this possible?

What is the best approach to do this within Needle Engine so I can load and unload the animations as needed without using up loads of memory with references to 99 animations I dont need at the time? I looked at AssetReferences, but they are for prefabs, and I am using AnimationClips as opposed to prefabed objects I want to load into a scene.

Any direction is appreciated.

Original Post on Discord

by user 259070246382469121

Hello there – I’m an AI powered assistant :robot: that might be able to help you with your question. Would you like me to try helping you?

How it works:
Reply to the messages of the bot that end with a thread_id to interact with it and ask follow-up questions. You can also mention the bot directly in this channel to get help.

Help requested: please wait a moment…

Here is what I found for you :brain: Discord

Hello Nostalgicbear,

To manage animations efficiently in the Needle Engine without using up unnecessary memory for unused animations, you can take advantage of the engine’s capability to support various Unity animation features. Needle Engine allows for the export of AnimationClips, including loop modes, and integration with the Timeline and Animator for state transitions (see the documentation).

While Needle Engine documentation doesn’t specify a direct equivalent to Unity’s Addressables or Resources folders, animations could still be separated into different glTF files and loaded on demand. This way, you only load the animations when they are necessary, similar to how you’d load assets from Addressables asynchronously in Unity.

Here’s how you could approach this:

  1. Export your animations into separate glTF files.
  2. Use AssetReference to reference these glTF files in your scripts.
  3. Instantiate or deserialize these assets dynamically, loading and unloading as needed, to manage the memory usage efficiently.

By doing so, you keep your main project’s file size small and only load additional assets when required. Please refer to the documentation section on exporting animations and AssetReferences to guide you through this process (see the documentation).

1 messages left GPT 4
thread_IBupeM8XtEReIpEDpPrigsm9

Hey @nostalgicbear when you reference prefabs in Unity from scripts and load them with AssetReference.instantiate everything is dynamic.
Even easier is to use the SceneSwitcher component to switch between things (disable the various options and just call it by API to set a specific index), which takes care of loading/unloading everything efficiently

E.g. https://app.songsofcultures.com/ uses this approach to split ~400 MB of data with tons of complex timelines, audio, animations to load very efficiently what’s needed – it’s pretty much just a SceneSwitcher component

Ah great thank you. I hadnt seen the SceneSwitcher component. I’ll take a look at that now. Thank you @herbst🌵

by user 259070246382469121

@herbst🌵 Is there a sample scene in your Unity samples that uses SceneSwitcher I can take a look at within Unity?

by user 259070246382469121

You can look at the MultiScene sample (it’s in our samples package)

It uses SceneAssets but you can also assign Prefabs

Thanks Marcel.

Ive been struggling with this for hours. After looking at the Multi Scenes example, I get that I can specify prefabs or assets to the SceneSwitcher. Thats fine for loading gameobjects, but Im struggling to understand how to make this work for my use case with animations.

I want to play out race paths in my racing game. I have an Animator which has an AnimatorController which has one single animation, lets say for RaceOption1. I want to be able to change the animation it plays out depending on what animation asset I load from the SceneSwitcher. So for example, it might play out RaceOption34.

I put together the following example to test but Ive had no luck:

  • Created a prefab to add to the SceneSwitcher

    • This prefab is a cube that has a script with a public variable for an Animator Controller which is set to auto play the new race path. Eg, this prefab contains an AnimatorController that holds the animation for RaceOption2. Another prefab contains an AnimatorController that holds RaceOption3 etc.
  • Assign the prefabs to the SceneSwitcher scenes list

  • When a prefab is loaded, it automatically finds the main Animator in my scene that controls the race outcome, and assigns its Animator Controller. So now the Race Animator should not be pointing to its default RaceOption1, because its newly updated runtime animator controller should now point at the new reference to whatever one was loaded via the SceneSwitcher.

I thought that would work as a test, but it doesnt. After I try the above I get the error in the attached image. I feel like my approach here is kinda dumb anyway. Is there an easier way to just specifically do the above with animations?


image.png

by user 259070246382469121

I’ve just seen that if I try and swap this at runtime, without using SceneSwitcher, just by assigning it a different controller directly via a script, I will always get the error in the message above. So in the image I have “Path” assigned. If I assign a different controller, the error is thrown. (The Animator is disabled and I only enable when I want a race to start). It seems that assigning while its disabled throws the error, but if I have it enabled, and I swap the controllers, there is no error but the animation doesnt play

by user 259070246382469121

Would you be able to report a bug with this issue kind of isolated?
Thanks!

Of course. I’ll report it when I’m back home in a more isolated way.

by user 259070246382469121

@herbst🌵 There appears to be a bug when trying to submit a bug report in Needle 3.22.6 (my test project) where it keeps endless popping up the dialog box prompting me to either Continue or Open the Description file. No matter what I press, it just keeps popping up the dialogue box and I have to kill Unity, so instead I have sent what was generated in the BugReports folder to you privately. Ill comment here in case you read this first.

by user 259070246382469121

Yes, I saw it –
would you mind updating your project and trying to submit a bug report from there? I haven’t seen this “dialog box loop” you’re mentioning so would be good to know if that happens persistently.

When you press open the description file do you see a markdown file opening in e.g. vscode (or your preferred text editor)?

I upgraded the project, and the bug report issue is gone, and the report has been submitted.

@marcel :cactus: Just to answer your question, yes the markdown file would open in Notepad, and I would fill it out, save, and then click “Continue” but instead of opening the next dialogue that allows you to actually submit it, it would constantly open a new markdown file template, and show the same dialogue box over and over. If I tried to close the dialogue box, the same would happen. Again, that was for Needle 3.22.6. That did not happen after I upgraded to 3.32.16

by user 259070246382469121

The dialogue should tell you why it re-opens (e.g. if the description of the bug is incomplete in the markdown file that opens) - but I agree that it should not do this indefinitely.

Do I understand correctly that 3.32 worked and doesnt have this problem? (we received your bugreport today)