Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

When a lot of Scriptable Object are too many?

Discussion in 'Scripting' started by Gerark87, Jun 14, 2020.

  1. Gerark87

    Gerark87

    Joined:
    Feb 2, 2013
    Posts:
    9
    Hello to everyone!

    After I followed all the important presentation videos and tutorials about Scriptable Object on the web I started to use them extensively.

    I also have the idea to create a Localization System where each instance of a localizable text is going to be a scriptable object instance. So I have 1 resource per translated text.

    This is very good because it helps me tracking how many texts are used in the game, how many of them are referenced and it's easy to create tools around them.

    But what happens if I start having thousands of texts? ( So thousands of scriptable objects ). What are the consequences on using too many Scriptable Object in that way? What I should pay attention to?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    I think... If it's currently working for you, stick with it. Things to watch out for would be large build sizes or memory footprints for your game, but realistically these objects will be peanuts compared to texture or sound files.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    I'm not sure there are a lot of consequences, other than how that feels like it could be a mess. I can't help but think how annoying it would be to try to actually find anything among those thousand files. Maybe you see a typo in some dialog and you want to go fix it. But because all of the text is somewhere in an asset, you can't easily search for it in your project. You'd need to resort to text searching in the file system perhaps.

    In general, I use scriptable objects for a lot of configuration and holding onto media, like audio clips. I don't think there's any reasons your approach wouldn't work, if that feels best to you. But I'd probably look for an alternate system first which may be easier to deal work with.
     
  4. Gerark87

    Gerark87

    Joined:
    Feb 2, 2013
    Posts:
    9
    Thank you for your answer. I think I'm just too worried and I just have to monitor how this thing evolve.

    I already created tools that help me with these potential issues. I can create and modify the scriptableobject directly from the editor and never touch the files ( if nothing goes terribly wrong :D ). Also I can export/import from/to CSV files the localized texts. So I'm quite ok with that. The benefit I get from Scriptable Object is that I enforce them to be referenced and never "Get by Code" so I have more control over it.
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    Okay, probably fine then. I don't know of any issues where you have to worry about having too many SOs, within reason. I would expect tens of thousands would be fine, though hopefully they're not all being referenced at the same time? It's worth profiling it a little just to see whether they contribute much to your game's memory usage.
     
    Gerark87 likes this.
  6. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,390
    There isn't any impact other than actually having to interface with the assets but you can create an editor tool to database the assets for you and never touch them directly for authoring and inspector extensions to make drop-down menus for them which makes referencing seamless.

    If you have a lot of content (localization) and do not build editor tools then the approach is objectively bad because of content volume, workflow difficulty and accessibility.

    I have a tool for this coming out soon as an inventory Asset but you can easily use it for databasing any content.
     
  7. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    the objects will take up ram, you can test it, try to create 10million objects and look your ram on task manager if it doesn't pass an amount you deem unacceptable create 10million more until you find your limit.
     
    Gerark87 likes this.
  8. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,390
    Only if you instantiate them. If you don't need copies (he shouldnt) then he's just reading a fixed asset in the build. Really, he's just reading strings inside the build so whatever he does with the string and managing accessing the prefab pointer is the memory cost. In any case, it shouldn't be a significant issue.
     
  9. Gerark87

    Gerark87

    Joined:
    Feb 2, 2013
    Posts:
    9
    Thank you for the answers!

    Probably I'm missing some information on how assets like scriptable object are loaded and maintained by the system. Could you point me to the right direction? Maybe just a link would clarify my doubts.
     
  10. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,390
    SO's aren't thoroughly documented (last I checked). Most of it is tribal knowledge and running your own tests for your use case to see if things work fine.
     
    Gerark87 likes this.
  11. Swimgod

    Swimgod

    Joined:
    May 7, 2018
    Posts:
    3
    Has having too many Scriptable Objects in the assets folder affected the reload time/reload script assemblies time for Unity?