SubScenes Live Link Convert Game View Question

Me again playing around with SubScenes & LiveLinkConvertGameView have a few more questions.

I wrote this very simple system as an exercise to try understand this whole concept and how it relates to what I want to do.

namespace Learn.Something
{

    //
    //IComponentData
    struct EntityCountComponent : IComponentData
    {
        public int entityCount;
    }

    struct EntityDataComponent : IComponentData
    {
        public int entityData;
    }

    //
    // GameObjectConversionSystem
    public class ConversionSystem : GameObjectConversionSystem
    {

        protected override void OnUpdate()
        {

            this.Entities.ForEach((TestProxy data) =>
            {
                Debug.Log("<b> <size=13> <color=#DE67DA>Info : 1 ConversionSystem : Converting Entities.</color> </size> </b>");

                var ePrimary = this.GetPrimaryEntity(data);

                var cData = new EntityCountComponent
                {
                    entityCount = data.numEntities
                };
                this.DstEntityManager.AddComponentData(ePrimary, cData);

            });
        }
    }

    //
    // ComponentSystem
    public class CreateSystem : ComponentSystem
    {

        private EntityQuery qEntityCount;
        private EntityQuery qEntityData;
        private EntityArchetype aEntityData;


        protected override void OnCreate()
        {

            aEntityData = EntityManager.CreateArchetype
            (
                ComponentType.ReadOnly<EntityDataComponent>()
            );

            qEntityData = GetEntityQuery
            (
                typeof(EntityDataComponent)
            );

            qEntityCount = GetEntityQuery
            (
                ComponentType.ReadOnly<EntityCountComponent>()
            );

            qEntityCount.SetFilterChanged(typeof(EntityCountComponent));
        }

        protected override void OnUpdate()
        {

            Entities.With(qEntityCount).ForEach((ref EntityCountComponent c) =>
            {

                Debug.Log("<b> <size=13> <color=#67A9DE>Info : 2 CreateSystem : Create Entities.</color> </size> </b>");

                EntityManager.DestroyEntity(qEntityData); // NOT VERY HAPPY WHERE THIS IS SITTING

                NativeArray<Entity> e = new NativeArray<Entity>(c.entityCount, Allocator.TempJob);
                EntityManager.CreateEntity(aEntityData, e);

                e.Dispose();

            });
        }
    }

    //
    // JobComponentSystem
    [UpdateAfter(typeof(CreateSystem))]
    public class UpdateSystem : JobComponentSystem
    {

        private EntityQuery qEntityData;


        protected override void OnCreate()
        {
            qEntityData = GetEntityQuery
            (
                typeof(EntityDataComponent)
            );

            qEntityData.SetFilterChanged(typeof(EntityDataComponent));
        }

        [BurstCompile]
        struct SetData : IJobForEachWithEntity<EntityDataComponent>
        {

            public void Execute(Entity entity, int index, ref EntityDataComponent c)
            {
                DebugInfo();

                c.entityData = index;
            }

            [BurstDiscard]
            private void DebugInfo()
            {
                Debug.Log("<b> <size=13> <color=#9DF155>Info : 3 SetDataSystem : Setting Data .</color> </size> </b>");
            }
        }


        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {

            inputDeps = new SetData
            {

            }.Schedule(qEntityData, inputDeps);

            return inputDeps;
        }
    }
}

Ok now looking at this video I you see my actions ( this gets a bit crazy but I need to understand this )

  1. In edit mode I open the subscene and I see the pink debug print for the GameObjectConversionSystem.- makes sense

  2. I edit my game object and I see the same thing - makes sense

  3. I save the subscene and I see the GameObjectConversionSystem execute twice - Why is that ?

  4. I enter play mode and the CreateSystem executes (dubug print blue) followed by the UpdateSystem printing a debug log for each entity in green - makes sense

5)I press edit on the sub scene at runtime and both the GameObjectConversionSystem & CreateSystem executes - Kind of make sense but would like some more info.

  1. I change my gameObj field numEntities and once again the GameObjectConversionSystem & CreateSystem executes - makes sense … but no UpdateSystem execution - Why is this ?

  2. At this point I can never get the UpdateSystem to execute, doesnt matter what I do - Why is this ?

Thanks in advance for entertaining my OCD.

So you’ve been struggling with this for a bit and I’m always a bit confused what you’re trying to do but I got a minute.
After loading your demo I see completely different, but still wrong, behaviour (i believe my systems are being ordered different).

Anyway so

EntityManager.DestroyEntity(qEntityData); // NOT VERY HAPPY WHERE THIS IS SITTING

is destroying the wrong entities here. You’re basically just destroying the entities you want to react to. If you are trying to cleanup up your old entities you’ll need to do it before this loop.

    public class CreateSystem : ComponentSystem
    {

        private EntityQuery qEntityCount;
        private EntityQuery qEntityData;
        private EntityArchetype aEntityData;

        protected override void OnCreate()
        {
            aEntityData = EntityManager.CreateArchetype(typeof(EntityDataComponent));
            qEntityCount = GetEntityQuery(ComponentType.ReadOnly<EntityCountComponent>());
            this.qEntityCount.SetFilterChanged(ComponentType.ReadOnly<EntityCountComponent>());
        }

        protected override void OnUpdate()
        {
            Entities.With(qEntityCount).ForEach((ref EntityCountComponent c) =>
            {
                Debug.Log("<b> <size=13> <color=#67A9DE>Info : 2 CreateSystem : Create Entities.</color> </size> </b>");

                EntityManager.CreateEntity(aEntityData, e);
            });

            EntityManager.DestroyEntity(qEntityCount);
        }
    }

This makes it so your entities are generated correctly. Be aware that with your current logic, every time you open/close subscene or make any change X number of new entities will be create. You need to clean up old entities (system state)

not really sure why you are not creating these entities in your conversion though.

Weird you got different behavior, do you have liveConvertGameView on ?

I found if I create these entities in the conversion system I loose control over them in the LiveLinkSystem (cant remember the exact name of that sys). That system seems to do things under the hood that in not clear to me. Maybe some comparison voodoo , I really dont know

The other drawback was the CreateAdditionalEntity is slower that the batch create in the ComponetSystem using a nativeArray. (Because i have to loop and use use CreateAdditionalEntity one at a time)

So the thought was to just keep one entity in the LiveLinkSystem (let call it a specs entity) and then that entity contains the amount of tile entities (EntityDataComponent) I need to build in a following ComponetSystem.

If my spec entity changed via gameObj and live link I would delete all my non specs entities (EntityDataComponent) and re create them and set their data. It all work apart for this setData step as the video shows. I can try deleting the spec entity eact time but i though I could simply just keep it synced via LiveLink

Am I using a flamethrower to lightly roast marshmallows

@tertle Looks like this might have been working but the Debug.Log() was not outputting to the console( only the first time and then stopped ). Good news is it working :slight_smile: sold 3 month effort pays off lol.
Any pro tips for Debug info from a Burst job ?

            public void Execute(Entity entity, int index, ref EntityDataComponent c)
            {
                DebugInfo(); // Yea , nah 

                c.entityData = index;
            }

            [BurstDiscard]
            private void DebugInfo()
            {
                Debug.Log("<b> <size=13> <color=#9DF155>Info : 3 SetDataSystem : Setting Data .</color> </size> </b>");
            }

don’t

turn off burst and step through with a debugger if you need