private void ReplaceSimWorld(SimulationWorld newWorld) { Log.Info($"Replacing sim world with new one (at tick {newWorld.GetLastTickIdFromEntity()})"); if (SimulationWorld != null) { if (_inPlayerLoop) { _tickSystem.RemoveFromPlayerLoop(SimulationWorld); _inPlayerLoop = false; } SimulationWorld.Dispose(); SimulationWorld = null; } SimulationWorld = newWorld; newWorld.Owner = this; _tickSystem.CreateSimSystemsAndAddToPlayerLoop(newWorld); _inPlayerLoop = true; SimWorldAccessor.SimWorld = newWorld.GetInternalAccessor().SimWorld; SimWorldAccessor.EntityManager = newWorld.GetInternalAccessor().EntityManager; SimWorldAccessor.SomeSimSystem = newWorld.GetInternalAccessor().SomeSimSystem; // could be any system HasJustRepacked = true; ReplaceVersion++; WorldReplaced?.Invoke(); }
protected override void OnDestroy() { base.OnDestroy(); if (SimulationWorld.IsCreated) { SimulationWorld.Dispose(); } SimWorldAccessor.SimWorld = null; SimWorldAccessor.EntityManager = default; SimWorldAccessor.SomeSimSystem = null; SimulationWorld = null; }