Search Unity

AssetReference<T> support

Discussion in 'Addressables' started by strich, Jul 16, 2018.

  1. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    375
    So we ended up writing our own solution to the asset problem some months ago and whilst we're pretty happy with it, it looks like Addressables is finally solving the problem more natively. Great!

    I have read the google doc and watched the talks. Whilst I like where it is going I cringed at the current inspector implementation - I'm not sure if that is just a WIP part of the package or not.

    For our implementation we successfully setup a ResourceRef<T> type that did practically all of the same things except that it gave the inspector enough information to draw the property correctly, as well as ensure the correct asset was being placed, etc etc.
     
  2. blurryroots

    blurryroots

    Joined:
    Apr 17, 2015
    Posts:
    3
    As far as I understood, you can archive type safety by using the attribute AssetReferenceTypeRestriction for which you can specify a list of types to be accepted by the AssetReference field.

    Code (CSharp):
    1. [AssetReferenceTypeRestriction(typeof(TypeA), typeof(TypeB))]
    2. public AssetReference Thing;
    3.  
     
  3. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    375
    Yeah, but that kind of sucks for writing code itself - With our solution all areas of the code that interact with the property know what type it is.
     
  4. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    559
    there is an
    AssetReferenceT<T>
    in the package. you have to create a
    [Serializable]
    non-generic subclass for it to be shown in the inspector.
    the package provides some subclasses for GameObject, Texture, and Sprite
     
    DougRichardson and SugoiDev like this.