How to access GameObject or Component from AssetReference?

Hi,

I’m trying to have an array of prefabs (loaded as assetReferences) and then accessing their components or normal things that we do with gameObjects.

But I don’t have a clue how to access them.

I tried this in order to have normal gameObjects and components access… but failed.

Any help?

public AssetReference assetToPlaceInScene;

    public AssetReference[] assetsToPlace;

    
    private List<GameObject> myObjects;

    //################

    private void Start()
    {
        //load single asset
        assetToPlaceInScene.LoadAssetAsync<GameObject>();

        //load array of assets? - Doesn't work
        assetsToPlace[].LoadAssetAsync<GameObject>();


        //load one item from the assetreference array - looks OK
        assetsToPlace[0].LoadAssetAsync<GameObject>();

        //assign assetReference loaded to GameObject List - Doesn't work
        myObjects[0] = assetsToPlace[0].LoadAssetAsync<GameObject>();

    }

Thanks for the support!!

Not quite certain what you are trying to do here, but the LoadAssetAsync produces a AsyncOperationHandle handle for the requests. For each item in your array, you need to make a request and then do something with the Result field if the operation was successful. Hope that helps a little.

        protected override void LoadContent()
        {
            Handle = Addressables.LoadAssetAsync<T>(Address);
            Handle.Completed += OnLoadComplete;
        }
      
        protected void OnLoadComplete(AsyncOperationHandle obj)
        {
            switch (obj.Status)
            {
                case AsyncOperationStatus.Succeeded:
                    {
                        CONTENT_TARGET = obj.Result as T;
                    }
                    break;
                case AsyncOperationStatus.Failed:
                    {
                        // FAILED
                    }
                    break;
            }
        }