andrew-raphael-lukasik / Prefab-System

`com.unity.entities 1.0`-compatible way to find (lookup) prefab entities
MIT License
4 stars 1 forks source link

Entity.Null after reboot scene #2

Open kostarevVP opened 8 months ago

kostarevVP commented 8 months ago

after restarting the scene with the entity prefabs, they become Null, but the entries in the dictionary remain, the problem was solved as follows

           [Unity.Burst.BurstCompile]
   partial struct RegisterPrefabPoolJob : IJobEntity
   {
       public EntityCommandBuffer ECB;
       public NativeHashMap<FixedString64Bytes, Entity> Prefabs;
       [ReadOnly] public FixedString128Bytes WorldName;
       public void Execute(in Entity entity, in DynamicBuffer<RequestPrefabPoolRegistration> buffer)
       {
           int numBefore = Prefabs.Count;
           foreach (var request in buffer)
           {
               if (Prefabs.TryAdd(request.PrefabID, request.Prefab))
               {
                   Debug.Log($"{WorldName} RegisterPrefabPoolJob: '{request.PrefabID}' prefab registered successfully.");
               }
               else
               {
                   if (Prefabs[request.PrefabID] == Entity.Null)
                   {
                       Prefabs[request.PrefabID] = request.Prefab;
                   }
                   else
                   {
                       Debug.LogWarning($"{WorldName} RegisterPrefabPoolJob: '{request.PrefabID}' prefab registration failed! Prefabs.Count ={Prefabs.Count}");
                   }
               }
           }
           int numAfter = Prefabs.Count;

           ECB.RemoveComponent<RequestPrefabPoolRegistration>(entity);
           ECB.DestroyEntity(entity);

           Debug.Log($"{WorldName} RegisterPrefabPoolJob: RequestPrefabPoolRegistration processed, {numAfter - numBefore} prefabs added");
       }
   }
andrew-raphael-lukasik commented 8 months ago

Hi @kostarevVP!

Thank you for investigating this. It would probably be the best if you could create a PR originating from #develop or #upm branch - I will then merge it so github will credit you as project contributor properly. I can add this code myself if you have no time for that ofc, let me know.

Have a good day

andrew-raphael-lukasik commented 7 months ago

Hi again @kostarevVP!

Can we arrange this as a PR? Or maybe you prefer me to do this instead?

Cheers!