You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 9, 2025. It is now read-only.
My projects make uses of adressable assets. Some scenes are adressables, some are not.
A problem appears when you want to share some ScriptableObjects (in my case, i will focus on Events) between scenes that are built as Addressable and "straight" scenes. Indeed, each one will embed a copy of the scriptable object when "packed". Hence, when an event is raised, GameEventListeners packed in addressables scenes won't respond because they hold a copy of the original game event, and this copy is obviously not raised. The only way to share a variable in this context is to use AddressableAssets.AssetReference. You can then use the referenced object, but you have to "load" it before being able to access it (otherwise you will encounter null reference).
Prior to discovering your asset, I used my own implementation that was basically a copycat of what Ryan Hipple showed in his talk.
But, to fit my needs I had added a basic AssetReference support.
usingUnityEngine;usingUnityEngine.AddressableAssets;usingUnityEngine.Events;publicclassGameEventListener:MonoBehaviour{/// <summary>/// The associated gamed event./// </summary>[SerializeField]privateGameEventEvent;/// <summary>/// The associated addressable game event./// </summary>[SerializeField]privateAssetReferenceAddressableEvent;/// <summary>/// The response to called when event occurs./// </summary>[SerializeField]privateUnityEventResponse;privateasyncvoidOnEnable(){// If both addressable event and local event are set then addressable event supersedes local event.if(AddressableEvent.RuntimeKeyIsValid()){awaitAddressableEvent.LoadAssetAsync<GameEvent>().Task;((GameEvent)AddressableEvent.Asset).RegisterListener(this);}else{Event.RegisterListener(this);}}privateasyncvoidOnDisable(){if(AddressableEvent.RuntimeKeyIsValid()){awaitAddressableEvent.LoadAssetAsync<GameEvent>().Task;((GameEvent)AddressableEvent.Asset).RegisterListener(this);}else{Event.UnregisterListener(this);}}/// <summary>/// Called when an event is raised./// </summary>publicvoidOnEventRaised(){Response?.Invoke();}}}
Is it worth to add support for AssetReference to Event listeners ?
Is somebody interested in ?
Is there a better way than my quick and dirty sample ?
The text was updated successfully, but these errors were encountered:
Hello, I'm just giving my take on this problem. If a scriptable object is an Addressable, and you want to have scene object to have the same reference as the one in Addressable, you can "fix" it by having your scene to be an Addressable too. So when Addressable is packing, it will reference the same object.
That means, scriptable object is Addressable, scene is an Addressable too. That solved my problem. However u will have to handle scene loading etc.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi, Thanks for your work on this asset !
My projects make uses of adressable assets. Some scenes are adressables, some are not.
A problem appears when you want to share some ScriptableObjects (in my case, i will focus on Events) between scenes that are built as Addressable and "straight" scenes. Indeed, each one will embed a copy of the scriptable object when "packed". Hence, when an event is raised, GameEventListeners packed in addressables scenes won't respond because they hold a copy of the original game event, and this copy is obviously not raised. The only way to share a variable in this context is to use AddressableAssets.AssetReference. You can then use the referenced object, but you have to "load" it before being able to access it (otherwise you will encounter null reference).
Prior to discovering your asset, I used my own implementation that was basically a copycat of what Ryan Hipple showed in his talk.
But, to fit my needs I had added a basic AssetReference support.
Is it worth to add support for AssetReference to Event listeners ?
Is somebody interested in ?
Is there a better way than my quick and dirty sample ?
The text was updated successfully, but these errors were encountered: