M
M
MishkaVNorky2018-11-14 13:04:49
C++ / C#
MishkaVNorky, 2018-11-14 13:04:49

References to objects (such as a manager), why does it immediately load everything into memory?

Hi friends, another interesting topic to think about.
Need help from those in the know.
The options are different, but let's say we have a ScriptableObject, it has only 1 variable.
List<GameObject> items;
For the test, I created a large sprite, 70 meters somewhere in memory. I put a Sprite Renderer on the stage, stuffed a sprite into it, made a prefab and deleted it.
Link to prefab added to ScriptableObject .
5bebf055b160b375492595.png
So why, even by simply loading this ScriptableObject from the resources (in which ONLY links to prefabs), HE IMMEDIATELY loads the entire game object into memory (in particular, it immediately loads the image from the Sprite Renderer). Moreover, I didn’t even do anything, didn’t create, didn’t initiate.
5bebefe52a237493905880.png
I want to make just a base from ScriptableObject so that it stores links to prefabs for a specific task.
PS I must say right away that it DOES NOT load anything from other places. Before pressing the test button, the image is NOT loaded, only after clicking (when the ScriptableObject is loaded from resources) the image is already loaded

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2018-11-14
@freeExec

That's the mechanics. Instantiateis not a download, but a copy, so the original must be downloaded by now. If you need to load exactly at the right moment, useResource.Load(path)

D
Daniil Basmanov, 2018-11-15
@BasmanovDaniil

When opening a scene and loading from resources, Unity searches for all related objects and loads them into memory, you can’t just store links without loading, you can only store self-made identifiers and load objects from resources using them when necessary. You can also try the Addressable Asset System , this package is a bit rough, but it can help.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question