Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to add a managed compnent to an Entity during authoring?

Discussion in 'Entity Component System' started by frankfringe, Aug 21, 2023.

  1. frankfringe

    frankfringe

    Joined:
    Feb 9, 2019
    Posts:
    83
    I have the following managed component

    Code (CSharp):
    1. public class MainConfig : IComponentData
    2. {
    3.    public List<string> RessourceNames;
    4.    public List<Building> Buildings;
    5. }
    When I try to use `AddComponent` I get

    Code (CSharp):
    1. The type 'MainConfig' must be valid unmanaged type (simple numeric, 'bool', 'char', 'void', enumeration type or struct type with all fields of unmanaged types at any level of nesting) in order to use it as a type argument for 'T' parameter
    How should I be adding this managed component during the authoring phase?
     
    bb8_1 likes this.
  2. frankfringe

    frankfringe

    Joined:
    Feb 9, 2019
    Posts:
    83
    The answer is

    Code (CSharp):
    1. AddComponentObject(e, config)
     
    bb8_1 likes this.