André Gasser
André Gasser

Reputation: 1105

Unity ScriptableObject Loading Behaviour

Let's assume I have the following two ScriptableObjects:

public class Topic : ScriptableObject
{
    public string Title;
    public Sprite TitleImage;
    public Level[] Levels;
}

public class Level : ScriptableObject 
{
    // Various level properties here (strings, Sprite, AudioClip, ...)
}

The game has multiple topics and every topic has multiple levels. Topic and Level exist as .asset files.

Now, when I build a topic selection screen in which I only need Topic.Title and Topic.TitleImage, what will Unity do with the ScriptableObjects referenced in the Levels field? Will that data be loaded?

Upvotes: 0

Views: 1485

Answers (1)

Empty
Empty

Reputation: 516

If Unity has a reference to an object from any other object loaded in memory, it will be loaded into memory.

So if you have anything in your Levels array it will be loaded, yes.

Generally this isn't an issue though, ScriptableObjects should be fairly lightweight, but you should be aware of what your references reference, for example if your Level contains a link to a GameObject prefab, anything that GameObject references will be loaded too, and this goes all the way down the chain.

Upvotes: 2

Related Questions