#How to use EntityQueryBuilder in OnCreate

1 messages · Page 1 of 1 (latest)

hollow otter
#

Vurst is complaining about memory buffer stuff
or atomics sometimes
only on the separate client editor
in the main editor it works flawlessly

I have tried all 3 of these versions, and it is complaining on all of them:

public void OnCreate(ref SystemState state) {
            var query = state.GetEntityQuery(
                ComponentType.ReadOnly<NetworkId>(),
                ComponentType.Exclude<NetworkStreamInGame>()
            );
            
            state.RequireForUpdate<PlayerPrefab>();
            state.RequireForUpdate(query);
        }
[BurstCompile]
        public void OnCreate(ref SystemState state) {
            var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<NetworkId>().WithNone<NetworkStreamInGame>();
            
            var query = state.GetEntityQuery(builder);
            
            state.RequireForUpdate<PlayerPrefab>();
            state.RequireForUpdate(query);
        }
var builder = new EntityQueryBuilder(Allocator.Temp).WithAll<NetworkId>().WithNone<NetworkStreamInGame>();
            
            state.RequireForUpdate<PlayerPrefab>();
            state.RequireForUpdate(state.GetEntityQuery(builder));
#

The whole script currently:

[BurstCompile, WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
    public partial struct ClientGameSystem : ISystem {
        public void OnCreate(ref SystemState state) {
            var query = state.GetEntityQuery(
                ComponentType.ReadOnly<NetworkId>(),
                ComponentType.Exclude<NetworkStreamInGame>()
            );
            
            state.RequireForUpdate<PlayerPrefab>();
            state.RequireForUpdate(query);
        }

        [BurstCompile]
        public void OnUpdate(ref SystemState state) {
            Debug.Log("ClientGameSystem: OnUpdate");
            
            var commandBuffer = SystemAPI.GetSingletonRW<EndSimulationEntityCommandBufferSystem.Singleton>().ValueRW.CreateCommandBuffer(state.WorldUnmanaged);

            foreach (var (netId, entity) in SystemAPI.Query<RefRO<NetworkId>>().WithEntityAccess().WithNone<NetworkStreamInGame>()) {
                Debug.Log($"ClientGameSystem: Found connection with NetworkId {netId.ValueRO.Value}, sending StartGameRequest");
                
                commandBuffer.AddComponent<NetworkStreamInGame>(entity);
                
                var req = commandBuffer.CreateEntity();
                
                commandBuffer.AddComponent<StartGameRequest>(req);
                commandBuffer.AddComponent(req, new SendRpcCommandRequest { TargetConnection = entity });
            }
        }
    }
#

and the current error is this:

ObjectDisposedException: Attempted to access BufferLookup<Unity.NetCode.IncomingCommandDataStreamBuffer> which has been invalidated by a structural change.
Unity.Entities.WorldUnmanagedImpl+UnmanagedUpdate_00001698$BurstDirectCall.Invoke (System.Void* pSystemState) (at <96ba2f197a6242da8fced8786a7e5bce>:0)
Unity.Entities.WorldUnmanagedImpl.UnmanagedUpdate (System.Void* pSystemState) <0x20abae09ec0 + 0x00052> in <96ba2f197a6242da8fced8786a7e5bce>:0
Unity.Entities.WorldUnmanagedImpl.UpdateSystem (Unity.Entities.SystemHandle sh) (at ./Library/PackageCache/com.unity.entities@8cc175c78756/Unity.Entities/WorldUnmanaged.cs:945)
Unity.Entities.ComponentSystemGroup.UpdateAllSystems () (at ./Library/PackageCache/com.unity.entities@8cc175c78756/Unity.Entities/ComponentSystemGroup.cs:725)
UnityEngine.Debug:LogException(Exception)
Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@8cc175c78756/Unity.Entities/Stubs/Unity/Debug.cs:17)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/com.unity.entities@8cc175c78756/Unity.Entities/ComponentSystemGroup.cs:740)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/com.unity.entities@8cc175c78756/Unity.Entities/ComponentSystemGroup.cs:693)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/com.unity.entities@8cc175c78756/Unity.Entities/SystemBase.cs:420)
Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at ./Library/PackageCache/com.unity.entities@8cc175c78756/Unity.Entities/ScriptBehaviourUpdateOrder.cs:523)

mellow ingot
#

your actual problem is probably elsewhere, try disabling burst to get a better stack trace

waxen pebble
hollow otter
#

bc it's not even running

#

the system i mean

waxen pebble
#

However, it is better not to use EndSimulationEntityCommandBufferSystem

hollow otter
#

also, it only happens when i use a MPPM client

hollow otter
#

but i failed and tried this

waxen pebble
hollow otter
#

oh

waxen pebble