docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Create a shared component

    Shared components can contain only unmanaged fields. To reference UnityEngine.Object instances in a shared component, use UnityObjectRef<T> fields.

    Before you create a shared component, make sure you understand how they work and their performance implications. Refer to Introducing shared components for an overview and when to use them, and Optimize shared components for performance considerations.

    Create an unmanaged shared component

    To create an unmanaged shared component, create a struct that implements the marker interface ISharedComponentData.

    The following code sample shows an unmanaged shared component:

    public struct ExampleUnmanagedSharedComponent : ISharedComponentData
    {
        public int Value;
    }
    

    To override the way that a shared component is checked for equality, you can implement the IEquatable<> interface, and ensure public override int GetHashCode() is implemented. Entities then internally uses these methods to compare shared components for equality, and therefore partitions entities differently that way. You can also put [BurstCompile] on these methods, and they will be compiled with Burst if they comply with Burst's restrictions.

    In This Article
    Back to top
    Copyright © 2026 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)