Struct ManagedAddressable<T>
A value-type RAII wrapper that holds a loaded Addressable asset and automatically releases the
underlying AsyncOperationHandle when the wrapper is disposed, ensuring that the
Addressables reference count is always properly decremented.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Addressables
Assembly: ScyllaCore.dll
Syntax
public struct ManagedAddressable<T> : IDisposable
Type Parameters
| Name | Description |
|---|---|
| T | The type of the managed asset (e.g. |
Remarks
Instances of this struct are created exclusively by LoadManagedAsync<T>(string, CancellationToken) and LoadManagedAsync<T>(AssetReference, CancellationToken). The internal constructor is not accessible from outside the assembly.
Lifetime. The wrapper takes ownership of the handle at construction time.
Calling Dispose() releases the handle exactly once; subsequent calls are
safe and are no-ops. After disposal, IsValid returns false and
accessing Asset throws InvalidOperationException.
Value-type copy semantics. Because this is a struct, assigning it to another
variable copies the handle reference, not the asset itself. Both copies share the same
underlying handle. Disposing either copy releases the shared handle, making the other
copy invalid. Avoid copying unless you are certain about ownership.
Implicit conversion. An implicit conversion to T is provided
for convenience. This triggers the same guard as Asset and will throw if the
wrapper has been disposed.
using (var managed = await ScyllaAddressables.LoadManagedAsync<Texture2D>("textures/player"))
{
renderer.material.mainTexture = managed.Asset;
} /* Asset automatically released here. */
Properties
Asset
Gets the loaded asset of type T.
Declaration
public T Asset { get; }
Property Value
| Type | Description |
|---|---|
| T | The result of the underlying |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when Dispose() has already been called, or when the underlying handle is no longer valid (e.g. released externally). |
Handle
Gets the raw AsyncOperationHandle that this wrapper manages.
Declaration
public AsyncOperationHandle<T> Handle { get; }
Property Value
| Type | Description |
|---|---|
| AsyncOperationHandle<T> | The handle passed to the constructor. May be invalid after Dispose() is called. Use this to pass the handle to Unity APIs that require it (e.g. progress polling), but do not release the handle manually - let Dispose() manage its lifetime. |
IsValid
Gets a value indicating whether this wrapper holds a valid, unreleased Addressables asset.
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
|
Methods
Dispose()
Releases the underlying Addressables handle, decrementing the asset's reference count. Subsequent calls after the first are safe no-ops.
Declaration
public void Dispose()
Remarks
After disposal, IsValid returns false and accessing Asset
will throw InvalidOperationException. The handle is only released if it is still valid
at the time of disposal, guarding against external releases.
TryGetAsset(out T)
Attempts to retrieve the loaded asset without throwing if the wrapper is disposed or invalid.
Declaration
public bool TryGetAsset(out T asset)
Parameters
| Type | Name | Description |
|---|---|---|
| T | asset | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|
Operators
implicit operator T(ManagedAddressable<T>)
Implicitly converts a ManagedAddressable<T> to its asset type, providing
syntactic convenience when passing managed assets to APIs that expect T.
Declaration
public static implicit operator T(ManagedAddressable<T> managed)
Parameters
| Type | Name | Description |
|---|---|---|
| ManagedAddressable<T> | managed | The managed addressable to convert. |
Returns
| Type | Description |
|---|---|
| T |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when the wrapper has been disposed or the underlying handle is invalid. This is the same exception that Asset throws. |