0

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?

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

You should have a look at loading resources to avoid that.
@derHugo Thanks for the link. As Resources.Load() is discouraged by Unity all that's left is AssetBundles. So yeah, at the moment I am not sure if I really need this.... Will have a look into it though.
If you need to have fine tune control of memory (something Unity is sadly kinda bad at) you need to look at AssetBundles for manually loading and unloading specific assets at runtime. But I wouldn't use those unless I really really had to. The references inside a particular Unity Scene aren't loaded either until you load the scene, so that is also an option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.