docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method GetUnsafeSystemRef

    GetUnsafeSystemRef<T>(SystemHandle)

    Resolves the system handle to a reference to its underlying system instantiation.

    Declaration
    public ref T GetUnsafeSystemRef<T>(SystemHandle id) where T : unmanaged, ISystem
    Parameters
    Type Name Description
    SystemHandle id

    The system handle

    Returns
    Type Description
    T

    A reference to the concrete ISystem compatible instance for this system

    Type Parameters
    Name Description
    T

    The system type

    Remarks

    This system reference is not guaranteed to be safe to use. If the system or world is destroyed then the reference becomes invalid and will likely lead to corrupted program state if used.

    Generally, instead of public member data, prefer using component data for system level data that needs to be shared between systems or externally to them. This defines a data protocol for the system which is separated from the system functionality.

    Private member data which is only used internally to the system is recommended.

    GetUnsafeSystemRef, though provided as a backdoor to system instance data, is not recommended for usage in production or any non-throwaway code, as it

    • encourages coupling of data and functionality
    • couples data to the system type with no direct path to decouple
    • does not provide lifetime or thread safety guarantees for data
    • does not provide lifetime or thread safety guarantees for system access through the returned ref
    Exceptions
    Type Condition
    InvalidOperationException

    Thrown if the system handle is invalid or does not belong to this world.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)