Skip to content

Latest commit

 

History

History
22 lines (18 loc) · 2.08 KB

File metadata and controls

22 lines (18 loc) · 2.08 KB

Addressables ComponentReference with DerivedClass

What is AssetReference?

Addressables AssetReference is a special reference to any asset in you project. You can control device memory and build dependencies by using AssetReference instead of native asset type (Sprite, GameObject etc.). See more at doc.

What is AssetReferenceT?

asset-types There is generic AssetReferenceT<TComponent> designed to make strictly typed asset variables. Your assets workflow become the same as Unity classic workflow this way.

How it works with GameObjects?
We can store only AssetReferenceT<GameObject> not to attached MonoBehaviour component. But classic Unity assets workflow supports reference to MonoBehaviour, so? Use ComponentReference<T>.

What is ComponentReference<T>?

ComponentReference is an Addressables extension to store AssetReference via Component attached to GameObject asset. Yes, like a classic Unity prefab. The ComponentReference<T> is a part of Basic Addressables code example doc.

Component derived class problem

Imagine you have some service creates Overlay from prefab list by generic type parameter. type-check Concrete overlay class inherits BaseOverlay but ComponentReference<ConcreteOverlay> is always not ComponentReference<BaseOverlay> cause generic-types specific.

Solution

okay

  1. Realise IComponentReference interface in BaseClass
  2. Get derived ConcreteClass type attached to prefab by GetDerivedComponentType() method.