Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

EntityManager.Instantiate is not adding the PhysicsCollider component

Discussion in 'Physics for ECS' started by whiitehead, Jul 5, 2020.

  1. whiitehead

    whiitehead

    Joined:
    Jan 24, 2020
    Posts:
    6
    I added the Physics Shape component to the original prefab in the editor and then when I use
    GameObjectConversionUtility.ConvertGameObjectHierarchy
    to convert it, the resulting entity has a PhysicsCollider component and I'm able to do a raycast on it.

    However, when I use
    EntityManager.Instantiate
    on it, the entity that is returned has a RenderMesh, Transform, and all that but it does not have a PhysicsCollider and I'm not able to raycast it.

    If I'm not providing enough information, just let me know and I can post some screens. This just seems like the kind of thing that is probably obvious to somebody on this forum.
     
  2. eneIr

    eneIr

    Joined:
    Nov 28, 2018
    Posts:
    15
    Have you tried to replace the Physics Shape Component in the prefab with box collider or capsule collider component?
     
  3. whiitehead

    whiitehead

    Joined:
    Jan 24, 2020
    Posts:
    6
    Thank you but that did not work.

    I have isolated the issue a bit further. The first part of what I said was false -- the

    GameObjectConversionUtility.ConvertGameObjectHierarchy
    does not add the PhysicsCollider component. However, the entity that is converted from the scene hierarchy does have a PhysicsCollider and that is what was triggering my raycasts.

    The following is the code I'm using to convert my prefabs into entities and none of the entities that are returned have the PhysicsCollider component. Does anybody have any ideas for how I can get the entities to have that component?

    roadPrefabs
    is a public field in the monobehaviour that I put the prefabs into from the editor.

    Code (CSharp):
    1.        
    2. eModels = new Dictionary<string, Entity>();
    3. var settings = GameObjectConversionSettings.FromWorld(defaultWorld, null);
    4. foreach (GameObject prefab in roadPrefabs) {
    5.      eModels.Add(prefab.name, GameObjectConversionUtility.ConvertGameObjectHierarchy(prefab, settings));
    6. }
    7.  
     
  4. whiitehead

    whiitehead

    Joined:
    Jan 24, 2020
    Posts:
    6
    I got everything working.

    I stopped using

    GameObjectConversionUtility.ConvertGameObjectHierarchy
    in my script and now I just put the prefab back in the hierarchy and have a custom authoring component that adds the entity to the
    eModels
    NativeHashMap in the system that will be placing them into the world.
     
    eneIr and petarmHavok like this.