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. Dismiss Notice

Splitting a ScriptableObject into parts and the impact on memory

Discussion in 'Scripting' started by Kyzlyk, Aug 21, 2023.

  1. Kyzlyk

    Kyzlyk

    Joined:
    Nov 25, 2022
    Posts:
    1
    My situation: I have an "ability" that has an implementation and a "cover" (icon, description, etc.). This ability is a ScriptableObject. The cover and the implementation are not related to each other, so I divided them into two different classes, let's call them "Card" and "Execution". There can be many such abilities (15, 20...), and if I divide the ability into "Card" and "Execution", the number of ScriptableObjects will be twice as large. The question is, won't this division double the memory usage (I mean the overhead of the ScriptableObject) and is it efficient to use ScriptableObjects for this purpose at all?
     
  2. DragonCoder

    DragonCoder

    Joined:
    Jul 3, 2015
    Posts:
    1,453
    That overhead will be negligible. Your ability as a human to keep track of a large number of SOs will falter long before even an entry level smartphone will...
    A few dozen won't be noticeable by any means.

    Also as usual when it comes to optimization quezfions: Profile it! There is a dedicated memory profiler package which gives you info on what needs memory. Possible that this change simply won't be noticeable though. I mean think of how much data fits into just a few kilobytes...
     
    Kyzlyk and stain2319 like this.
  3. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,317
    Split objects will take more memory, but the amount of overhead will be tiny for modern system. To make it noticeable, you'll need hundreds of thousands or millions of objects.
     
    Kyzlyk likes this.
  4. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,724
    As mentioned, the overhead will be negligible. The things you're describing would be measured in bytes, for the most part. Maybe kilobytes.

    Not gigabytes. Not megabytes.

    Kilobytes and bytes.
     
    Ryiah, spiney199 and Kyzlyk like this.