Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by fomartin · Aug 08, 2020 at 05:19 PM · transformparentcomponentbug-perhapsdots

Does the Parent component get removed from Entity if its Value is not set?

Practicing some ECS and tried to make a system where an object is set as the child of an entity it collides with. Until then it flies through the air without a Parent component. Think an arrow flying through the air but becoming a child of an Enemy entity so that it appears stuck on them.

So I thought I'd just add the Parent component to the arrow in my component authoring script, but not set Value to anything. But then it happened, the entity that I added the Parent component before didn't have it anymore on time of collision. I am sure that I do not have any remove component calls anywhere, so unless there is some weird DOTS gotcha that certain unset components are removed then I wouldn't know what's up. So I tried setting the Parent component to different values:


  • struct default

  • Entity.Null

  • itself

  • some manager entity (essentially was thinking of having a manager of sorts to keep count and pool these entities so thought I'd just set the Parent to that.


The first 3 had the same problem of the Parent component disappearing. The last worked, but messed with the physics of the entity so it was not clean solution.


So yeah, is there something I may be missing here? I ended up learning about EntityCommandBuffers to add a Parent component on collision within a job, but I'm still confused as to why my previous approach didn't work.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by andrew-lukasik · Aug 09, 2020 at 11:18 AM


You may want to read the MANUAL to understand how these things work in ECS now.


In short - No, there is no such system that removes invalid Parent components - at least in Entities 0.13.0. But to inspect that yourself, go to ...\Projec_Name\Library\PackageCache\com.unity.entities@0.13.0-preview.24\Unity.Transforms directory, look for files ending with ...System and read their source code yourself.


For a reference, this is how you can setup a working parent-child transform relationship:

 using UnityEngine;
 using Random = UnityEngine.Random;
 
 using Unity.Mathematics;
 using Unity.Entities;
 using Unity.Transforms;
 
 public class Test : MonoBehaviour
 {
 
     World world = default(World);
     EntityManager command = default(EntityManager);
 
     Entity PARENT = Entity.Null;
     Entity CHILD = Entity.Null;
 
     void Start ()
     {
         world = World.DefaultGameObjectInjectionWorld;
         command = world.EntityManager;
         
         // CREATE PARENT ENTITY:
         PARENT = command.CreateEntity(
             typeof(LocalToWorld) ,
             typeof(Translation) ,
             typeof(Rotation) ,
             typeof(Scale)
         );
         command.SetName( PARENT , "parent" );
         command.SetComponentData( PARENT , new LocalToWorld{
             Value = float4x4.identity
         } );
         command.SetComponentData( PARENT , new Translation{
             Value = Random.onUnitSphere
         } );
         command.SetComponentData( PARENT , new Rotation{
             Value = Random.rotation
         } );
         command.SetComponentData( PARENT , new Scale{
             Value = 1f
         } );
 
         // CREATE CHILD ENTITY:
         CHILD = command.CreateEntity(
             typeof(LocalToWorld) ,
             typeof(LocalToParent) ,
             typeof(Parent)
         );
         command.SetName( CHILD , "child" );
         command.SetComponentData( CHILD , new LocalToWorld{
             Value = float4x4.identity
         } );
         command.SetComponentData( CHILD , new LocalToParent{
             Value = float4x4.TRS( Random.onUnitSphere , Random.rotation , Random.onUnitSphere )
         } );
         command.SetComponentData( CHILD , new Parent{
             Value = PARENT
         } );
     }
 
     void Update ()
     {
         var LTW = command.GetComponentData<LocalToWorld>( PARENT );
         {
             float t = (float) math.sin( UnityEditor.EditorApplication.timeSinceStartup );
             LTW.Value = math.mul( LTW.Value , float4x4.Translate( new float3{ x=t , y=t , z=t } ) );
         }
         command.SetComponentData( PARENT , LTW );
     }
 
 }
Comment
Add comment · Show 1 · 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
avatar image fomartin · Aug 09, 2020 at 06:03 PM 0
Share

Thanks for the link and sample code, but I already know how to set a Parent, as I mentioned (albeit implicitly) in my description. I tagged as "bug-perhaps" because it was being removed if I didn't set a "valid" parent. So if this is not intended behavior, as you said, then there may be a bug or some edge case gotcha that isn't being being expressed in the manual or forums.

Still, you technically answered my question so marking as correct. Thanks :)

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

171 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

Related Questions

Getting screenshots within a loop? 2 Answers

Problem transferring children to a new parent 2 Answers

Model rotation and hierarchy of game objects - not rotating! 1 Answer

Parent colliding bullet to the object 1 Answer

Offset transform.parent.position - Help 1 Answer


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