Struct AddressableResult<T>
Represents the outcome of an Addressables operation that returns an asset or other
typed value. On success, Value holds the loaded asset; on failure,
the value is default(T) and error details are available through
ErrorCode, ErrorMessage, and Exception.
Inherited Members
Namespace: Scylla.Core.Util.Addressables
Assembly: ScyllaCore.dll
Syntax
public readonly struct AddressableResult<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of the result value. For asset-loading operations this is typically a
Unity |
Remarks
AddressableResult<T> follows the same result-pattern contract as
AddressableResult but adds the Value property and
helpers GetValueOrDefault(T) and TryGetValue(out T) for
convenient value extraction. Methods that return this type never throw
AddressableException under normal failure conditions.
Instances are created exclusively via the static factory methods Success(T), Failure(AddressableErrorCode, string, Exception), and FromException(AddressableException). The constructor is private.
To strip the type parameter and obtain a plain AddressableResult with the same success/failure state (e.g., for a caller that only cares whether the operation succeeded), call ToResult().
Properties
ErrorCode
Gets the structured error code that categorizes the failure, or
Unknown when IsSuccess is
true. Use this to implement targeted retry or fallback logic without
string-parsing ErrorMessage.
Declaration
public AddressableErrorCode ErrorCode { get; }
Property Value
| Type | Description |
|---|---|
| AddressableErrorCode |
ErrorMessage
Gets a human-readable description of why the operation failed, or null
when IsSuccess is true. Suitable for debug logging but
not for programmatic branching - use ErrorCode for that.
Declaration
public string ErrorMessage { get; }
Property Value
| Type | Description |
|---|---|
| string |
Exception
Gets the exception that caused the failure if one was available at the point of
capture, or null when the failure arose from a non-exception code path
or when the operation succeeded. When non-null, this is typically an
AddressableException wrapping a Unity AsyncOperationHandle
exception.
Declaration
public Exception Exception { get; }
Property Value
| Type | Description |
|---|---|
| Exception |
IsFailure
Gets a value indicating whether the Addressables operation encountered an error.
This is the logical inverse of IsSuccess. When true, inspect
ErrorCode for the structured failure category and
ErrorMessage for a human-readable description.
Declaration
public bool IsFailure { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsSuccess
Gets a value indicating whether the Addressables operation completed without error.
When true, Value contains the loaded asset and all error
fields carry no meaningful information.
Declaration
public bool IsSuccess { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Value
Gets the loaded asset or operation output when the operation succeeded. When
IsFailure is true this property returns default(T)
- which is
nullfor reference types and the zero-initialized value for value types. Always check IsSuccess before accessing this property directly, or use GetValueOrDefault(T) or TryGetValue(out T) for safe extraction.
Declaration
public T Value { get; }
Property Value
| Type | Description |
|---|---|
| T |
Methods
Failure(AddressableErrorCode, string, Exception)
Creates an AddressableResult<T> that represents a failed operation
with the given error code. Value is set to default(T).
The ErrorMessage is taken from the explicit
errorMessage argument when provided; otherwise a default
message is generated from errorCode.
Declaration
public static AddressableResult<T> Failure(AddressableErrorCode errorCode, string errorMessage = null, Exception exception = null)
Parameters
| Type | Name | Description |
|---|---|---|
| AddressableErrorCode | errorCode | The AddressableErrorCode that categorizes the failure. |
| string | errorMessage | An optional human-readable description of the failure. When |
| Exception | exception | The exception that caused the failure, if available. May be |
Returns
| Type | Description |
|---|---|
| AddressableResult<T> | A new AddressableResult<T> with IsSuccess set to
|
FromException(AddressableException)
Creates a failed AddressableResult<T> from an existing
AddressableException, preserving its
ErrorCode,
Message, and the exception itself as
Exception. Value is set to default(T).
When exception is null, the result uses
Unknown and a generic message.
Declaration
public static AddressableResult<T> FromException(AddressableException exception)
Parameters
| Type | Name | Description |
|---|---|---|
| AddressableException | exception | The AddressableException to convert into a result. May be
|
Returns
| Type | Description |
|---|---|
| AddressableResult<T> | A new AddressableResult<T> with IsSuccess set to
|
GetValueOrDefault(T)
Returns Value when the operation succeeded, or the specified
defaultValue when it failed. This is a safe alternative to
accessing Value directly without checking
IsSuccess first.
Declaration
public T GetValueOrDefault(T defaultValue = default)
Parameters
| Type | Name | Description |
|---|---|---|
| T | defaultValue | The value to return when IsFailure is |
Returns
| Type | Description |
|---|---|
| T |
Success(T)
Creates an AddressableResult<T> that represents a successful
operation. IsSuccess will be true and Value
will hold the provided asset. ErrorCode is set to
Unknown as a neutral sentinel, and
ErrorMessage and Exception are both null.
Declaration
public static AddressableResult<T> Success(T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | The loaded asset or operation result to carry in the success result. For reference
types this may be |
Returns
| Type | Description |
|---|---|
| AddressableResult<T> | A new AddressableResult<T> with IsSuccess set to
|
ToResult()
Converts this typed AddressableResult<T> to a non-generic AddressableResult with the same success or failure state. The asset value is discarded. This is useful when passing the result to a method that only cares whether the operation succeeded, not what it returned.
Declaration
public AddressableResult ToResult()
Returns
| Type | Description |
|---|---|
| AddressableResult | A Success() result when IsSuccess
is |
TryGetValue(out T)
Attempts to retrieve the operation result value using the try-get pattern. Unlike accessing Value directly, this method expresses intent clearly when callers want to branch on success/failure without a separate IsSuccess check.
Declaration
public bool TryGetValue(out T value)
Parameters
| Type | Name | Description |
|---|---|---|
| T | value | When this method returns |
Returns
| Type | Description |
|---|---|
| bool |
|