Here’s the scenario in the Editor. I drag and drop an object (asset) as a reference into a variable in the Inspector.
How do I do the same in code (c#)?
I could use Resources.Load - but is that loading the asset into memory taking up resources, when all I want is a reference? Or is the drag & drop into the Inspector also loading the asset into memory; ie. not just a reference to the object/asset?
A “drag & drop” in the inspector does load the referenced asset into memory as soon as the object referencing it is loaded.
To go around this issue, we implemented a WeakReference class, where in the Inspector it shows up as a normal asset field, but in background only saves a string to the Resources path. It means the asset is not loaded, until we actually want it to be.
Thank you
that’s exactly the information I needed. Sometimes it helps to just understand how Unity does something, and what the pros/cons are. I am now using Resources.Load for the reference, and also a weaker reference system too.