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

How to set “useGravity” for Rigidbody to entities in Unity

Discussion in 'Entity Component System' started by ZM14, Jun 26, 2018.

  1. ZM14

    ZM14

    Joined:
    Feb 2, 2017
    Posts:
    3
    For the position you can use something like this:
    Code (CSharp):
    1. [Inject] private ComponentDataFromEntity<Position> _position;


    But cant use it for Rigidbody. How to access the parameters for Rigidbody for entities?
     
  2. dstilwagen

    dstilwagen

    Joined:
    Mar 14, 2018
    Posts:
    36
    You can try the EntityManager extension method GetComponentObject<T>(entity) I use it to change the color of an entities SpriteRenderer. You can also use ComponentArray<Rigidbody>() in a struct for use with [Inject].
     
  3. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    116
    Rigidbody is of type Component (legacy) not ComponentData (ECS). Keep that in mind when trying to use the API.