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

Split up large loadable stuff from ScriptableObject?

Discussion in 'Editor & General Support' started by apps_skoolbo, Jul 22, 2019.

  1. apps_skoolbo

    apps_skoolbo

    Joined:
    Jun 14, 2019
    Posts:
    2
    Hi all, I'm a Unity noob who's been playing around with ScriptableObjects. I got a bit carried away and I ended up created a large and nested ScriptableObject (SO) that defines all of the AI characters in my game. Problem is that this definition includes prefabs, audio files, materials and images.

    I should've thought about this earlier but it completely slipped my mind that Unity loads all objects referenced in SOs into memory when the SO is added to the scene. This is great for front loading assets but I'm looking to keep a relatively low memory footprint, especially for texture memory as I'm targeting some old mobile devices with limited texture RAM.

    Now I could split out these large files onto a separate SOs, place them into Resources and add in file paths in their stead, but this method would involve introducing a lot of magic strings into the mix. Plus if the files were to move for whatever reason, the path references would need to be manually updated. One of the best things about Unity is that when a file moves, all of its references are updated accordingly and I'd be remiss to not take advantage of that as much as possible.

    So, does anyone have a better solution for this problem? Noob-ish question but is there a way to refer to a file/prefab/audio/image without loading it onto the memory in a non-magic stringy way?
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,227
  3. apps_skoolbo

    apps_skoolbo

    Joined:
    Jun 14, 2019
    Posts:
    2
    Thanks for the suggestion, it's an almost perfect solution but it looks like Addressables no longer support synchronous loading which is a problem for me. It would force some quite a bit of refactoring and overhauling of my how my scenes and my current loading system work. So I'd have to do more research and planning before committing to this method. Too bad it no longer supports synchronous loading like Resources.Load though.
     
  4. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,276
    You can make wrappers for handling async stuff synchronously. (Although it would be cool to have it built in someday)
     
    karl_jones likes this.