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. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Physics "Getting Started" documentation sample throws exception

Discussion in 'DOTS Physics' started by pragmascript, Nov 4, 2019.

  1. pragmascript

    pragmascript

    Joined:
    Dec 31, 2010
    Posts:
    101
    I am tryiyng to get the ECS Physics Getting Started sample to work using Unity 2019.2.

    Using the exact code from:

    Creating bodies from scratch


    When this line is being executed:


    entityManager.AddComponentData(entity, new Translation { Value = position });


    The following exception is raised:


    ArgumentException: The component of type:Translation has already been added to the entity.
    Unity.Entities.EntityComponentStore.AssertCanAddComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/EntityComponentStoreDebug.cs:232)
    Unity.Entities.EntityManager.AddComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType, System.Boolean ignoreDuplicateAdd) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/EntityManagerChangeArchetype.cs:697)
    Unity.Entities.EntityManager.AddComponentData[T] (Unity.Entities.Entity entity, T componentData) (at Library/PackageCache/com.unity.entities@0.1.1-preview/Unity.Entities/EntityManagerChangeArchetype.cs:404)
    SpawnPhysics.CreateBody (Unity.Rendering.RenderMesh displayMesh, Unity.Mathematics.float3 position, Unity.Mathematics.quaternion orientation, Unity.Entities.BlobAssetReference`1[T] collider, Unity.Mathematics.float3 linearVelocity, Unity.Mathematics.float3 angularVelocity, System.Single mass, System.Boolean isDynamic) (at Assets/_Scripts/ECS/SpawnPhysics.cs:55)
    SpawnPhysics.Start () (at Assets/_Scripts/ECS/SpawnPhysics.cs:30)
     
    Last edited: Nov 4, 2019
    steveeHavok likes this.
  2. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    Thanks for the headsup on this. We'll get it fixed and add a simple sample that uses the docs code to make sure it stays correct. You can just change entityManager.AddComponentData to SetComponentData instead, if the component is already there. The entityManager.HasComponent is useful to check if you need to Add or Set a ComponentData
     
    pragmascript likes this.