Search Unity

ConvertToEntity in prefab creates PhysicsCollider,

Discussion in 'Physics for ECS' started by AnmAtAnm, Feb 28, 2020.

  1. AnmAtAnm

    AnmAtAnm

    Joined:
    Nov 2, 2019
    Posts:
    3
    Well.... y'all can ignore this one. It works. Sometime between when I started this post and when I returned to the code it started working. No explanation, and thus no learning opportunity. Frustrated by moving on.
    ===============================================================

    I'm attempting to follow the pong tutorial using 2019.3.3f1, Entities 0.6.0, and UnityPhysics 0.2.5.

    All was working well until the last step, where the GameManager spawns the ball via GameObjectConversionUtility.ConvertGameObjectHierarchy(..). If I manually place the ball prefab into the scene, the ball behaves as expected. However, the ball entity spawned by the GameManager does not bounce off the walls or paddles.

    Looking through the Entity Debugger, the unnamed ball entity created by the GameManager does not have a PhysicsCollider. , where the one named "ball" from the scene does have it. This explains the behavior, but is obviously not desirable. I expected either prefab conversion mechanism to lead to the same result.

    The ball prefab has a sphere Physics Shape. I also tried it with an additional Sphere Collider, with no difference.

    This looks similar to a thread from December, but I'm not using EntityArchetype.

    The relevant snippets from my GameManager code:
    Code (CSharp):
    1.  
    2. private void Awake()
    3. {
    4.     // ...
    5.     World world = World.DefaultGameObjectInjectionWorld;
    6.     manager = world.EntityManager;
    7.  
    8.     blobAssetStore = new BlobAssetStore();
    9.     GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(world, blobAssetStore);
    10.     ballEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(ballPrefab, settings);
    11.     //...
    12. }
    13.  
    14. void SpawnBall()
    15. {
    16.     Entity ball = manager.Instantiate(ballEntityPrefab);
    17.     Debug.Log("ball = " + ball);
    18.  
    19.     Vector3 dir = new Vector3(
    20.         UnityEngine.Random.Range(0, 2) == 0 ? -1 : 1,
    21.         UnityEngine.Random.Range(-.5f, .5f),
    22.         0).normalized;
    23.     Vector3 speed = dir * ballSpeed;
    24.  
    25.     PhysicsVelocity velocity = new PhysicsVelocity()
    26.     {
    27.         Linear = speed,
    28.         Angular = float3.zero
    29.     };
    30.     manager.AddComponentData(ball, velocity);
    31. }

    Any clues on what I'm missing?
     
    Last edited: Feb 28, 2020