0
\$\begingroup\$

I’ve looked at several tutorials regarding Addressables and it seems that loading an asset revolves around referencing it in the inspector, loading it in, and then finally instantiating it but putting this to use so far has been very confusing for me.

Let’s say I have a handful of GameObjects in one of my scenes and they all depend on different assets and have a fixed position in my scene:

  1. Does the Addressables system automatically mark every dependency under that GameObject (Texture2D, animations, Materials etc.) as an addressable?
  2. What if I wanted to load only a Texture2D that a GameObject depends on in which that GameObject already sits in a scene? In an extreme example, I tried to mark a Texture2D that was like 100MB as an Addressable and tried to do LoadAssetAsync with the push of a button but the asset was still being used even without pushing any button to load it.
  3. If I want to load several different GameObjects that are supposed to have several different fixed positions in the scene then what’s an easier way to make sure they are positioned correctly instead of instantiating after loading and then repositioning? Making a root GameObject and parenting all of the aforementioned GameObjects under it and then instantiating the root would work but that’s just so impractical to do so every time.
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I'd recommend in future trying to limit posts here to one question at a time. This makes it easier and faster to get good, in-depth answers. I've tried to answer all three points below, since it looks like at least the first two are connected to the same misunderstanding. In general though, posts containing multiple different questions may be placed on hold until they're edited to focus on a single question at a time. \$\endgroup\$ Commented Dec 5, 2024 at 19:37

1 Answer 1

0
\$\begingroup\$
  1. When one object is loaded — whether as an addressable or otherwise — all of its dependencies are loaded too. That's not quite the same as marking all the dependencies as addressables themselves, since the dependencies may not have their own addressable keys for you to reference individually if you didn't set them up that way. They just get pulled along for the ride when you load any object that depends on them.

  2. Marking an asset as addressable does not force all loads of that asset to be deferred. The addressable system gives you an alternative path to vanilla loading for you to use manually when appropriate; it does not override that default behaviour.

    If the asset is placed in the scene or referenced directly (i.e. not via its addressable AssetReference, label, or key) by anything in the scene (or anything directly referenced by something in the scene, recursively), then it will be loaded with that scene.

    You get deferred loading only when you don't put the asset or anything that depends on it in the scene, and instead reference it solely using the addressables system (as an AssetReference, label, or key), then explicitly load it via that addressing method when you want it to actually get loaded.

  3. I'd solve this by making an AddressableLocator script that we'll place on an otherwise-empty game object. This script will hold the address of the addressable prefab and, on command, will load and instantiate that addressable object at the position and orientation where you placed the locator in the scene (or in its containing prefab).

    To make it easier to accurately position these locators while editing the scene, you can give them an [ExecuteInEditMode] function that instantiates a preview copy of the addressable you've assigned as a child, but marks it to not save with the scene, and deletes this preview child when changing scenes or entering play mode. This lets you preview where the addressable object will be spawned, while ensuring it's not added as a dependency for the scene to load automatically: you maintain control over when to load and instantiate it by calling the locator's spawn method.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.