Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by manyshotsshort · Apr 27, 2020 at 01:26 AM · physicsdots

Cannot move anything with pure ECS Physics instantiation

I am messing around with unity's new physics and learning ECS at the same time. My hope was to spawn a whole lot of spheres via ECS and have physics move them (as in initially just respond to gravity). Everything I try thus far does nothing.

I can add a normal gameobject sphere, attach a physics body, physics shape, and convert to entity script in same scene and that one drops like it should. I've mirrored all the components I found in the entity debugger from the gameobject sphere version in the pure ECS ones and they still don't move.

Does anyone have example code somewhere or can spot whats wrong with my simple script?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Unity.Entities;
 using Unity.Transforms;
 using Unity.Rendering;
 using Unity.Collections;
 using Unity.Physics;
 using Unity.Mathematics;
 
 public class GameManager : MonoBehaviour
 {
 
     [SerializeField]
     UnityEngine.Material mat;
     [SerializeField]
     Mesh mesh;
 
     // Start is called before the first frame update
     void Start()
     {
         EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
 
         EntityArchetype eArch = em.CreateArchetype(
             typeof(Translation),    // gives it a transform
             typeof(RenderMesh),     // gives it a renderer
             typeof(RenderBounds),   // needed with render mesh
             typeof(LocalToWorld),   // gives it world coordinates
             typeof(PhysicsMass),    // add mass to the objects
             typeof(PhysicsDamping), // not sure
             typeof(PhysicsVelocity),// allow moving
             typeof(PhysicsCollider),// bang into stuffs
             typeof(Ball));
 
         NativeArray<Entity> eArr = new NativeArray<Entity>(3000, Allocator.Temp);
 
         em.CreateEntity(eArch, eArr);
 
         for(int i=0; i < eArr.Length; i++)
         {
             Entity e = eArr[i];
             // my dummy component
             em.SetComponentData(e, new Ball { damage = 10 });
             // spawn randomly somewhere
             em.SetComponentData(e, new Translation
             {
                 Value = new Unity.Mathematics.float3(UnityEngine.Random.Range(-50, 50),
                 UnityEngine.Random.Range(-100, 0),
                 UnityEngine.Random.Range(-50, 50))
             });
 
             // init a dynamic mass, then set the values that apparently dont get intialized.
             PhysicsMass pm = PhysicsMass.CreateDynamic(new Unity.Physics.MassProperties(), 10);
             pm.InverseInertia = new float3(6f, 6f, 6f);
             pm.InverseMass = 1.0f;
 
             em.SetComponentData(e,pm);
 
             // little dampening
             em.SetComponentData(e, new PhysicsDamping
             {
                 Angular = 0.05f,
                 Linear = 0.01f
             });
 
             // not sure if this needs any initializing, but exists on GO sphere version.
             em.SetComponentData(e, new PhysicsCollider
             {
             });
 
             // initial velocity to resist gravity some?
             em.SetComponentData(e, new PhysicsVelocity
             {
                 Angular = new float3(0.0f, 0.0f, 0.0f),
                 Linear = new float3(0.0f, 10.0f, 0.0f)
             });
 
             
             // setup rendermesh
             em.SetSharedComponentData(e, new RenderMesh
             {
                 material = mat,
                 mesh = mesh
             });
         }
 
         eArr.Dispose();
     }
 }
 
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image merobbins5 · Jun 26, 2020 at 06:40 PM 0
Share

I have the same problem. Did you ever find a solution?

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by wiiiteekk · Oct 04, 2020 at 07:19 AM

Hi @manyshotsshort

I found a solution. To make a dynamic body you have to set it mass properly. And to set mass you have to create collider first. This is how I am adding rigid body dynamically

 Entities.WithAll<EnableSimulation_TAG>().ForEach((Entity e, int entityInQueryIndex, in Translation translation, in PhysicsCollider collider) => {
     // the most important part here:        
     PhysicsMass pm = PhysicsMass.CreateDynamic(collider.MassProperties, 1.2f);
     ecb.AddComponent<PhysicsMass>(entityInQueryIndex, e, pm);
 
     ecb.AddComponent<PhysicsVelocity>(entityInQueryIndex, e, new PhysicsVelocity {
         Linear = new float3(0.00f, 0, 0)
     });
 
     ecb.AddComponent<PhysicsDamping>(entityInQueryIndex, e, new PhysicsDamping {
         Linear = 0.0f
     });
 
 
     ecb.RemoveComponent<EnableSimulation_TAG>(entityInQueryIndex, e);
 }).ScheduleParallel();
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

208 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Physics Unity Classic vs Physics Unity Dots 1 Answer

Dots physics ComputePenetration equivalent 1 Answer

DOTS trigger event is firing twice? 0 Answers

Unity (ECS & DOTS) Entity Sinking 0 Answers

Unity DOTS Physics constraint linear and angular x,y,z 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies 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.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges