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

Resolved How do you use the parent/child in ECS? (IBufferElementData)

Discussion in 'Entity Component System' started by FederalRazer89, Aug 28, 2023.

  1. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    Version:
    Unity: 2022.2.5f
    Burst: 1.8.2
    Entities: 1.0.0-pre.15

    Hello

    I want to be able to handle child and parent entities for attaching weapons/items to characters or vehicle.
    In Mono i could just make the item a child or directly just edit the transform of the item through a reference to the GameObject.

    I have tried a bit of testing for parent and children to work but i will need to do a lot more testing to understand it. Especially since i cant find a good example which i can understand more easily.

    At the moment i have haven't really done research and testing on IBufferElementData, didnt think i would need it at this stage. But i encounter several situations were a parent/child solution would be better.

    In this example i found on github, i shows how the syntax works, but i don't know what this function is intended to do.
    https://github.com/Unity-Technologi...Samples/Assets/Common/Scripts/EntitySender.cs

    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using Unity.Entities;
    4. using UnityEngine;
    5.  
    6. public interface IReceiveEntity
    7. {
    8. }
    9.  
    10. public struct SentEntity : IBufferElementData
    11. {
    12.     public Entity Target;
    13. }
    14.  
    15. public class EntitySender : MonoBehaviour
    16. {
    17.     public GameObject[] EntityReceivers;
    18.  
    19.     class EntitySenderBaker : Baker<EntitySender>
    20.     {
    21.         public override void Bake(EntitySender authoring)
    22.         {
    23.             var sentEntities = AddBuffer<SentEntity>();
    24.             foreach (var entityReceiver in authoring.EntityReceivers)
    25.             {
    26.                 List<MonoBehaviour> potentialReceivers = new List<MonoBehaviour>();
    27.                 GetComponents<MonoBehaviour>(entityReceiver, potentialReceivers);
    28.                 foreach (var potentialReceiver in potentialReceivers)
    29.                 {
    30.                     if (potentialReceiver is IReceiveEntity)
    31.                     {
    32.                         sentEntities.Add(new SentEntity() {Target = GetEntity(entityReceiver)});
    33.                     }
    34.                 }
    35.             }
    36.         }
    37.     }
    38. }
    39.  
    40.  


    Can i get a simple example that can show how to use parent and child in ECS? Especially how to work with IBufferElementData, accessing child components and other relevant stuff. Have tried searching but i have found old examples that didn't help my understanding. Any help would be appreciated.
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,556
    In Unity ECS, just simply set parent entity component, with it's realtive entity.
    Unity ECS system will handle the rest. Including assigning children to relevant parents.
     
  3. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83

    Thanks for the response.
    I have started creating a test environment, for testing and stuff. My first testing with trying to create a entity with a child with a prefab, failed.
    I am just trying see what the correct way to setup parent /child is, and if i can adapt it to my current work flow with prefabs.

    And accessing the child requires the use of dynamic buffer. At this point i am not sure of how to interact with dynamic buffer.


    I going to test some more later then i can post some code so people can see what i don't understand.
     
  4. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    I tested just simply adding a GameObject through a subscene and that created a parent and children like @Antypodish said.

    But when i try to do it at runtime, i can't get it work.

    I want to be able to add, remove children and change parents at runtime. And i plan to have a lot of procedural systems.

    Any suggestion to what i am doing wrong, or is it that changing parents and children can't be done during runtime?


    Added via Subscene (Works)
    upload_2023-8-29_10-49-53.png

    Added during runtime (Don't create children)
    upload_2023-8-29_10-50-35.png


    Code (CSharp):
    1.  
    2. public class ParentTesting : MonoBehaviour
    3. {
    4.     public GameObject parentGO;
    5.     public GameObject childFirst;
    6.     public GameObject childSecond;
    7.  
    8.  
    9.     public class ParentTestingBaker : Baker<ParentTesting>
    10.     {
    11.         public override void Bake(ParentTesting authoring)
    12.         {
    13.             //var parentEntity = AddBuffer<ParentBufferData>();
    14.  
    15.             AddComponentObject(new ParentTestingClass
    16.             {
    17.                 parent = authoring.parentGO,
    18.                 childFirst = authoring.childFirst,
    19.                 childSecond = authoring.childSecond,
    20.  
    21.                 parentEntity = GetEntity(authoring.parentGO),
    22.             });
    23.  
    24.  
    25.  
    26.         }
    27.     }
    28. }
    29.  


    Code (CSharp):
    1.  
    2. public class ParentTestingClass : IComponentData
    3. {
    4.  
    5.     public GameObject parent;
    6.     public GameObject childFirst;
    7.     public GameObject childSecond;
    8.  
    9.     public Entity parentEntity;
    10.  
    11. }
    12.  


    Code (CSharp):
    1.  
    2. public partial class ParentTestingSystem : SystemBase
    3. {
    4.  
    5.     public bool testDebug = true;
    6.  
    7.     protected override void OnStartRunning()
    8.     {
    9.        
    10.     }
    11.  
    12.     protected override void OnUpdate()
    13.     {
    14.  
    15.         Entities.ForEach
    16.         ((ParentTestingClass parentTestingClass) =>
    17.         {
    18.             if (testDebug == true)
    19.             {
    20.                 Entity newEntity = EntityManager.Instantiate(parentTestingClass.parentEntity);
    21.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(newEntity, new FixedString64Bytes(" New Parent "));
    22.  
    23.                 EntityManager.AddComponent<Parent>(newEntity);
    24.  
    25.                 Debug.Log("ParentTestingClass spawned  ");
    26.                 testDebug = false;
    27.             }
    28.  
    29.  
    30.         }
    31.         ).WithStructuralChanges().WithoutBurst().Run();
    32.  
    33.     }
    34.  
    35. }
    36.  
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    Parent entity is missing (or invalid).

    - Add some debug steps at baking.
    - Check what entity is added & what is inside the component.
    Also, you don't need managed components for this.
    - Check what entity is being added as parent in the system.
     
    Antypodish likes this.
  6. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    The managed components is just for testing.

    I think i was able to create children during runtime, based on this thread.
    Create parent-child at runtime - Unity Forum

    Now i just need to learn and test how to access child entities.
    upload_2023-8-29_12-14-24.png

    Code (CSharp):
    1.  
    2. public class ParentTesting : MonoBehaviour
    3. {
    4.     public GameObject parentGO;
    5.     public GameObject childFirst;
    6.     public GameObject childSecond;
    7.  
    8.  
    9.     public class ParentTestingBaker : Baker<ParentTesting>
    10.     {
    11.         public override void Bake(ParentTesting authoring)
    12.         {
    13.             //var parentEntity = AddBuffer<ParentBufferData>();
    14.  
    15.             AddComponentObject(new ParentTestingClass
    16.             {
    17.                 parent = authoring.parentGO,
    18.                 childFirst = authoring.childFirst,
    19.                 childSecond = authoring.childSecond,
    20.  
    21.                 parentEntity = GetEntity(authoring.parentGO),
    22.                 childFirstEntity= GetEntity(authoring.childFirst),
    23.                 childSecondEntity= GetEntity(authoring.childSecond),
    24.  
    25.  
    26.             });
    27.  
    28.  
    29.  
    30.         }
    31.     }
    32. }
    33.  


    Code (CSharp):
    1.  
    2. public class ParentTestingClass : IComponentData
    3. {
    4.  
    5.     public GameObject parent;
    6.     public GameObject childFirst;
    7.     public GameObject childSecond;
    8.  
    9.     public Entity parentEntity;
    10.     public Entity childFirstEntity;
    11.     public Entity childSecondEntity;
    12.  
    13.  
    14.  
    15.  
    16. }
    17.  


    Code (CSharp):
    1.  
    2.     protected override void OnUpdate()
    3.     {
    4.  
    5.         Entities.ForEach
    6.         ((ParentTestingClass parentTestingClass) =>
    7.         {
    8.             if (testDebug == true)
    9.             {
    10.  
    11.                 var parentPrefab = parentTestingClass.parentEntity;
    12.                 var parent = EntityManager.Instantiate(parentPrefab);
    13.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(parent, new FixedString64Bytes(" New Parent Test two "));
    14.  
    15.                 var childPrefab1 = parentTestingClass.childFirstEntity;
    16.                 var child1 = EntityManager.Instantiate(childPrefab1);
    17.  
    18.                 var childPrefab2 = parentTestingClass.childSecondEntity;
    19.                 var child2 = EntityManager.Instantiate(childPrefab2);
    20.  
    21.                 EntityManager.AddComponentData(child1, new Parent { Value = parent });
    22.                 EntityManager.AddComponentData(child1, new LocalTransform()
    23.                 {
    24.                     Position = new float3(parentTestingClass.parent.transform.position)
    25.          
    26.                 });
    27.  
    28.                 EntityManager.AddComponentData(child2, new Parent { Value = parent });
    29.                 EntityManager.AddComponentData(child2, new LocalToWorld()
    30.                 {
    31.                     Value = new float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
    32.  
    33.                 });
    34.  
    35.                 // Set Rotation on parent
    36.  
    37.  
    38.  
    39.                 Debug.Log("ParentTestingClass spawned  ");
    40.                 testDebug = false;
    41.             }
    42.  
    43.  
    44.         }
    45.         ).WithStructuralChanges().WithoutBurst().Run();
    46.  
    47.     }
    48.  
    49. }
    50.  
     
  7. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    Tried to access the child component from my created parent, but i get this error below. Not really sure how to approach this error. Any suggestion would be nice.

    Code (CSharp):
    1.  
    2. InvalidOperationException: No suitable code replacement generated, this is either due to generators failing, or lack of support in your current context
    3. ParentTestingSystem.ParentTestingSystem_3E95A25C_LambdaJob_0_LambdaBody (ParentTestingClass parentTestingClass) (at Temp/GeneratedCode/Assembly-CSharp/ParentTesting__System_2056218616.g.cs:80)
    4. ParentTestingSystem+ParentTestingSystem_3E95A25C_LambdaJob_0_Job.RunWithStructuralChange (Unity.Entities.EntityQuery query) (at Temp/GeneratedCode/Assembly-CSharp/ParentTesting__System_2056218616.g.cs:44)
    5. ParentTestingSystem.ParentTestingSystem_3E95A25C_LambdaJob_0_Execute () (at Temp/GeneratedCode/Assembly-CSharp/ParentTesting__System_2056218616.g.cs:92)
    6. ParentTestingSystem.OnUpdate () (at Assets/Scenes/Testing Parent/ParentTesting.cs:84)
    7. Unity.Entities.SystemBase.Update () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:428)
    8. Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:670)
    9. UnityEngine.Debug:LogException(Exception)
    10. Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/Stubs/Unity/Debug.cs:19)
    11. Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:675)
    12. Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ComponentSystemGroup.cs:628)
    13. Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/SystemBase.cs:416)
    14. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.15/Unity.Entities/ScriptBehaviourUpdateOrder.cs:526)
    15.  
    16.  

    This code cause error (Total system show it in context)
    Code (CSharp):
    1.  
    2.             if (EntityManager.HasBuffer<Child>(parentMain) && (testDebug == 10)) // <------------------- This line cause Error
    3.             {
    4.                 var test = SystemAPI.GetBuffer<Child>(parentMain);
    5.  
    6.                    
    7.                 Debug.Log(" test.Length " + test.Length);
    8.             }      
    9.  


    Code (CSharp):
    1.  
    2. public partial class ParentTestingSystem : SystemBase
    3. {
    4.  
    5.     public int testDebug = 0;
    6.     public Entity parentMain;
    7.     public Entity child1;
    8.     public Entity child2;
    9.  
    10.  
    11.     protected override void OnStartRunning()
    12.     {
    13.         testDebug = 0;
    14.     }
    15.  
    16.     protected override void OnUpdate()
    17.     {
    18.  
    19.         Entities.ForEach
    20.         ((ParentTestingClass parentTestingClass) =>
    21.         {
    22.             if (testDebug == 1)
    23.             {
    24.  
    25.                 var parentPrefab = parentTestingClass.parentEntity;
    26.                 parentMain = EntityManager.Instantiate(parentPrefab);
    27.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(parentMain, new FixedString64Bytes(" New Parent Test two "));
    28.                 Debug.Log("ParentTestingClass spawned  ");
    29.  
    30.                 var childPrefab1 = parentTestingClass.childFirstEntity;
    31.                 child1 = EntityManager.Instantiate(childPrefab1);
    32.  
    33.                 var childPrefab2 = parentTestingClass.childSecondEntity;
    34.                 child2 = EntityManager.Instantiate(childPrefab2);
    35.  
    36.                 EntityManager.AddComponentData(child1, new Parent { Value = parentMain });
    37.                 EntityManager.AddComponentData(child1, new LocalTransform()
    38.                 {
    39.                     Position = new float3(parentTestingClass.parent.transform.position)
    40.          
    41.                 });
    42.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(child1, new FixedString64Bytes(" New child1 Test two "));
    43.  
    44.  
    45.                 EntityManager.AddComponentData(child2, new Parent { Value = parentMain });
    46.                 EntityManager.AddComponentData(child2, new LocalToWorld()
    47.                 {
    48.                     Value = new float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
    49.  
    50.                 });
    51.                 EntityManager.AddComponent<ChildTestData>(child2);
    52.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(child2, new FixedString64Bytes(" New child2 Test two "));
    53.  
    54.  
    55.  
    56.  
    57.             }
    58.  
    59.            
    60.             if (EntityManager.HasBuffer<Child>(parentMain) && (testDebug == 10)) // <------------------- This line cause Error
    61.             {
    62.                 var test = SystemAPI.GetBuffer<Child>(parentMain);
    63.  
    64.                    
    65.                 Debug.Log(" test.Length " + test.Length);
    66.             }            
    67.              
    68.              
    69.  
    70.  
    71.  
    72.  
    73.         }
    74.         ).WithStructuralChanges().WithoutBurst().Run();
    75.  
    76.  
    77.  
    78.  
    79.         testDebug = testDebug + 1;
    80.     }
    81.  
    82. }
    83.  
     
  8. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    SystemAPI cannot be used from inside of EFE. Use EntityManager.GetBuffer<T>.
     
    FederalRazer89 likes this.
  9. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    Thanks, that solved it.


    Working code
    Code (CSharp):
    1.  
    2. public partial class ParentTestingSystem : SystemBase
    3. {
    4.  
    5.     public int testDebug = 0;
    6.     public Entity parentMain;
    7.     public Entity child1;
    8.     public Entity child2;
    9.  
    10.  
    11.     protected override void OnStartRunning()
    12.     {
    13.         testDebug = 0;
    14.     }
    15.  
    16.     protected override void OnUpdate()
    17.     {
    18.  
    19.         Entities.ForEach
    20.         ((ParentTestingClass parentTestingClass) =>
    21.         {
    22.             if (testDebug == 1)
    23.             {
    24.  
    25.                 var parentPrefab = parentTestingClass.parentEntity;
    26.                 parentMain = EntityManager.Instantiate(parentPrefab);
    27.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(parentMain, new FixedString64Bytes(" New Parent Test two "));
    28.                 Debug.Log("ParentTestingClass spawned  ");
    29.  
    30.                 var childPrefab1 = parentTestingClass.childFirstEntity;
    31.                 child1 = EntityManager.Instantiate(childPrefab1);
    32.  
    33.                 var childPrefab2 = parentTestingClass.childSecondEntity;
    34.                 child2 = EntityManager.Instantiate(childPrefab2);
    35.  
    36.                 EntityManager.AddComponentData(child1, new Parent { Value = parentMain });
    37.                 EntityManager.AddComponentData(child1, new LocalTransform()
    38.                 {
    39.                     Position = new float3(parentTestingClass.parent.transform.position)
    40.          
    41.                 });
    42.                 EntityManager.AddComponent<ChildTestData>(child1);
    43.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(child1, new FixedString64Bytes(" New child1 Test two "));
    44.  
    45.  
    46.                 EntityManager.AddComponentData(child2, new Parent { Value = parentMain });
    47.                 EntityManager.AddComponentData(child2, new LocalToWorld()
    48.                 {
    49.                     Value = new float4x4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
    50.  
    51.                 });
    52.                 EntityManager.AddComponent<ChildTestData>(child2);
    53.                 World.DefaultGameObjectInjectionWorld.EntityManager.SetName(child2, new FixedString64Bytes(" New child2 Test two "));
    54.  
    55.  
    56.  
    57.  
    58.             }
    59.  
    60.             /**/
    61.             if (EntityManager.HasBuffer<Child>(parentMain) && (testDebug == 10)) // <------------------- This line cause Error
    62.             {
    63.                 var test = EntityManager.GetBuffer<Child>(parentMain);
    64.                 var getComponent = EntityManager.GetComponentData<ChildTestData>(test[0].Value);
    65.  
    66.                 Debug.Log(" test.Length " + test.Length);
    67.                 Debug.Log(" test.Length " + test[0] + "  component:  " + getComponent);
    68.  
    69.             }
    70.  
    71.  
    72.  
    73.  
    74.  
    75.  
    76.         }
    77.         ).WithStructuralChanges().WithoutBurst().Run();
    78.  
    79.  
    80.  
    81.  
    82.         testDebug = testDebug + 1;
    83.     }
    84.  
    85. }
    86.  
     
  10. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    I encountered a problem when i am trying to parent a weapon to a character. The weapon is a parent and have some child entities and the character don't.

    My current knowledge is enough solve this problem my own way, but is it possible to structure the parent/child hierarchy similar to the Mono example below?

    Example of intended structure in Mono
    upload_2023-9-7_4-55-1.png


    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Unity.Burst;
    5. using Unity.Entities;
    6. using Unity.Mathematics;
    7. using Unity.Transforms;
    8. using Unity.Collections;
    9. using Unity.Physics;
    10. using UnityEngine;
    11.  
    12.  
    13. public partial class InteractionSystem : SystemBase
    14. {
    15.  
    16.  
    17.     protected override void OnUpdate()
    18.     {
    19.         EntityCommandBuffer ecb = new EntityCommandBuffer(Allocator.Temp);
    20.         EntityQueryBuilder builder = new EntityQueryBuilder(Allocator.Temp).WithAll<PhysicsWorldSingleton>();
    21.  
    22.         var singletonPhysicsQuery = World.DefaultGameObjectInjectionWorld.EntityManager.CreateEntityQuery(builder);
    23.         var collisionWorld = singletonPhysicsQuery.GetSingleton<PhysicsWorldSingleton>().CollisionWorld;
    24.  
    25.         //Look at interation and pick up for Player
    26.         Entities.ForEach
    27.             ((PlayerCameraClass playerCameraClass, ref PlayerInputData playerInputData, ref Entity entity, in LocalTransform localTransform) =>
    28.             {
    29.  
    30.  
    31.                 ECSRaycastTools.CustomRayCast customRayCast= new ECSRaycastTools.CustomRayCast()
    32.                 {
    33.                     collisionWorld = collisionWorld,
    34.                 };
    35.  
    36.                 var ray = playerCameraClass.playerCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2,0));
    37.                 float3 startPosition = new float3(ray.origin);
    38.                 float3 direction = new float3(ray.GetPoint(5));
    39.                 Unity.Physics.RaycastHit raycastHit = new Unity.Physics.RaycastHit();
    40.  
    41.                 bool raycastBool = customRayCast.CheckRay(startPosition, direction, out raycastHit, ECSRaycastTools.CustomCollisionLayers.InteractionObject, ECSRaycastTools.CustomCollisionLayers.InteractionObject);
    42.                 if ((raycastBool == true))
    43.                 {
    44.  
    45.  
    46.                     if ((World.DefaultGameObjectInjectionWorld.EntityManager.HasComponent<InteractionData>(raycastHit.Entity) == true) && (playerInputData.inputInteration == true))
    47.                     {
    48.                         var test = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<InteractionData>(raycastHit.Entity);
    49.                         var weaponParent = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<Parent>(raycastHit.Entity).Value;
    50.                         var objectType = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<ObejctData>(weaponParent).objectType;
    51.                         playerInputData.inputInteration = true;
    52.  
    53.                         if ((playerInputData.inputInteration == true) && (test.interactionType == EnumObjects.InterationType.pickItem))
    54.                         {
    55.                             Debug.Log(" Working ");
    56.  
    57.                             ecb.SetComponent(raycastHit.Entity, new InteractionData
    58.                             {
    59.                                 interactionType = EnumObjects.InterationType.inventory,
    60.                             });
    61.  
    62.                             ecb.AddComponent(weaponParent, new Parent // <==================  Adding to character
    63.                             {
    64.                                 Value = entity,
    65.                             });
    66.                             ecb.AddComponent(weaponParent, new LinkingTestComponent
    67.                             {
    68.                                 parent = entity,
    69.                                 position = localTransform.Position,
    70.  
    71.                             });
    72.  
    73.  
    74.                         }
    75.                         Debug.Log("Hit " + test + "  parent " + weaponParent + "  Parent ObjectType  " + objectType + "  playerInputData.inputInteration  " + playerInputData.inputInteration);
    76.                     }
    77.  
    78.  
    79.                     /*
    80.                                         bool buttonDown = false;
    81.                                         if (playerInputData.inputInteration == true)
    82.                                         {
    83.                                             buttonDown = true;
    84.                                             playerInputData.interationDuration = playerInputData.interationDuration + 0.01f;
    85.                                         }
    86.                                         else
    87.                                         {
    88.                                             if ((World.DefaultGameObjectInjectionWorld.EntityManager.HasComponent<InteractionData>(raycastHit.Entity) == true) && (playerInputData.inputInteration == true))
    89.                                             {
    90.                                                 var test = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<InteractionData>(raycastHit.Entity);
    91.                                                 var parent = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<Parent>(raycastHit.Entity).Value;
    92.                                                 var objectType = World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData<ObejctData>(parent).objectType;
    93.                                                 buttonDown = true;
    94.  
    95.                                                 if ((buttonDown == true) && (playerInputData.interationDuration >= 1) && (test.interactionType == EnumObjects.InterationType.pickItem))
    96.                                                 {
    97.                                                     Debug.Log(" Working " + "  interationDuration  " + playerInputData.interationDuration);
    98.                                                     test.interactionType = EnumObjects.InterationType.inventory;
    99.                                                     ecb.AddComponent(parent, new Parent { Value = entity });
    100.                                                 }
    101.                                                 Debug.Log("Hit "  + test + "  parent " + parent + "  Parent ObjectType  " + objectType);
    102.                                             }
    103.  
    104.                                             playerInputData.interationDuration = 0;
    105.                                         }
    106.                                         //Debug.Log("playerInputData.interationDuration  " + playerInputData.interationDuration);
    107.                     */
    108.  
    109.  
    110.                 }
    111.  
    112.                 Debug.DrawLine(startPosition, direction);
    113.             }
    114.             ).WithoutBurst().WithStructuralChanges().Run();
    115.  
    116.  
    117.         //Inventory
    118.         builder.Dispose();
    119.         ecb.Playback(EntityManager);
    120.         ecb.Dispose();
    121.     }
    122.  
    123. }
    124.  
    125. public struct LinkingTestComponent : IComponentData
    126. {
    127.     public Entity parent;
    128.     public float3 position;
    129.  
    130. }
    131.  
    132.  


    Left is the weapon entity and the right is the character entity. The character didn't get a parent component, but the LinkingTestComponent on the weapon identify the correct entity.
    upload_2023-9-7_4-45-54.png
     
  11. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,976
    I'll admit, what you are seeing is weird. But then again, you are using an experimental version of Entities and not the latest 1.0.14. How do I know? Because WorldTransform doesn't exist in the latest Entities. I suspect that your character not having a LocalToWorld could be part of the problem, but I don't remember all the details from that buggy mess.
     
    FederalRazer89 likes this.
  12. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    Thanks for the reply, will see if adding LocalToWorld when i spawn character might work. Otherwise i will update to the latest version, but there are several things that i know will break.

    Was planning to update when i finished some thing.
     
    Last edited: Sep 7, 2023
  13. FederalRazer89

    FederalRazer89

    Joined:
    Nov 24, 2019
    Posts:
    83
    Adding LocalToWorld solved it.

    upload_2023-9-8_3-47-0.png

    Now i can finish my prototype and most of my test before updating to latest version.

    Thanks for the help.