General purpose components | Package Manager UI website
docs.unity3d.com
    Show / Hide Table of Contents

    General purpose components

    ComponentData in Unity (also known as a component in standard ECS terms) is a struct that contains only the instance data for an entity. ComponentData should not contain methods beyond utility functions for acessing the data in the struct. All game logic and behaviour should be implemented in systems. To put this in terms of the old Unity system, this is somewhat similar to an old Component class, but one that only contains variables.

    Unity ECS provides an interface called IComponentData that you can implement in your code.

    IComponentData

    Traditional Unity components (including MonoBehaviour) are object-oriented classes which contain data and methods for behavior. IComponentData is a pure ECS-style component, meaning that it defines no behavior, only data. IComponentData is a struct rather than a class, meaning that it is copied by value instead of by reference by default. You will usually need to use the following pattern to modify data:

    var transform = group.transform[index]; // Read
    
    transform.heading = playerInput.move; // Modify
    transform.position += deltaTime * playerInput.move * settings.playerMoveSpeed;
    
    group.transform[index] = transform; // Write
    

    IComponentData structs may not contain references to managed objects. Since the all ComponentData lives in simple non-garbage-collected tracked chunk memory.

    See file: /Packages/com.unity.entities/Unity.Entities/IComponentData.cs.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023