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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

one-frame blink after creation a new entity

Discussion in 'Entity Component System' started by mr-gmg, Mar 2, 2020.

  1. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    62
    When I select a unit, I add a new selection entity as a child for that unit, but for a short little frame, I can see the new selection object at zero point.
    Code (CSharp):
    1. protected override JobHandle OnUpdate(JobHandle inputDeps) {
    2.     EntityCommandBuffer.Concurrent commandBuffer = m_endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent();
    3.     Entity prefabEntity = m_selectionHighlightingPrefab.value;
    4.     JobHandle highlightHandle = Entities.WithAll<Selected>().WithNone<HasSelectionHighlighting>().ForEach((Entity entity, int entityInQueryIndex) => {
    5.         commandBuffer.AddComponent(entityInQueryIndex, entity, new HasSelectionHighlighting());
    6.        
    7.         Entity newEntity = commandBuffer.Instantiate(entityInQueryIndex, prefabEntity);
    8.         commandBuffer.AddComponent(entityInQueryIndex, newEntity, new Parent{Value = entity});
    9.         commandBuffer.AddComponent(entityInQueryIndex, newEntity, new LocalToParent());
    10.         commandBuffer.AddComponent(entityInQueryIndex, newEntity, new Translation{Value = {y = 0.01f}});
    11.         commandBuffer.AddComponent(entityInQueryIndex, entity, new ChildSelectionHighlighting{value = newEntity});    
    12.     }).Schedule(inputDeps);
    13.     highlightHandle.Complete();
    14.     return highlightHandle;
    15. }
    16.  
    Any idea how to fix that?
     
  2. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    This is due to LocalToWorld set from Translation in the next frame. You can prevent this by setting LocalToWorld directly when spawning!
     
    mr-gmg likes this.
  3. mr-gmg

    mr-gmg

    Joined:
    Aug 31, 2015
    Posts:
    62
    thank you, it works!
     
    daschatten likes this.