Switch Scenes Using ECS

how to switch between scene without change anything.

i use old way script to changes scene

    public void StarGame()
    {
        SceneManager.LoadScene("MainScene");
    }

and this is a way out

    public void GTOMainMenu()
    {
        var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
        entityManager.DestroyEntity(entityManager.UniversalQuery);
        SceneManager.LoadScene("StartScene");
    }

with or without DestroyEntity nothing change

9839115--1415610--ECSVed.gif

it not work, i found the problem i use the Isystem for spawn capsule i want spawn only 5 unit then i use state.enable = false for update once but when i reload scene it not use spawn system
this is my script for spawn capsule

using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Transforms;
using Unity.Mathematics;
using Unity.Collections;
using Unity.Burst;
using UnityEngine;


public partial struct SpawnSystem : ISystem
{
    private GameManagerComponentData gameManager;
    private EntityManager entityManager;
  

    public void OnCreate(ref SystemState state)
    {
        Debug.Log("here2");
        state.RequireForUpdate<SpawnData>();
        entityManager = state.EntityManager;

    }
    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        Debug.Log(state.Enabled);
            var unitNumberAdd = 1;
            var entities = entityManager.GetAllEntities();

            foreach (var entity in entities)
            {
                if (entityManager.HasComponent<GameManagerComponentData>(entity))
                {
                    var battleMgr = entityManager.GetComponentData<GameManagerComponentData>(entity);
                    gameManager = battleMgr;
                }
            }
        state.Enabled = false;
        var spawnData = SystemAPI.GetSingleton<SpawnData>();
            var blueunitTransform = state.EntityManager.GetComponentData<LocalTransform>(spawnData.blueUnit);
            var redunitTransform = state.EntityManager.GetComponentData<LocalTransform>(spawnData.redUnit);
            var gridSize = 2;
            for (int i = 0; i < spawnData.unitCount; i++)
            {
                int row = i / gridSize;
                int col = i % gridSize;
                var blueSpawnEntity = state.EntityManager.Instantiate(spawnData.blueUnit);
                var redSpawnEntity = state.EntityManager.Instantiate(spawnData.redUnit);
                blueunitTransform.Position.x = row * 1.5f;
                blueunitTransform.Position.z = col * 1.5f;
                redunitTransform.Position.x = row * 1.5f;
                redunitTransform.Position.z = col * 1.5f + 10f;
                state.EntityManager.SetComponentData(blueSpawnEntity, blueunitTransform);
                var componentData = state.EntityManager.GetComponentData<UnitComponentData>(blueSpawnEntity);
                var componentDataRed = state.EntityManager.GetComponentData<UnitComponentData>(redSpawnEntity);

                componentData.hp = gameManager.HP;
                componentData.attackDamage = gameManager.Attack;
                componentData.attackRange = gameManager.AttackRange;
                componentData.attackSpeed = gameManager.AttackSpeed;
                componentData.movementSpeed = gameManager.MovementSpeed;
                componentData.unitNum = unitNumberAdd;
                unitNumberAdd++;


                state.EntityManager.SetComponentData(blueSpawnEntity, componentData);
                state.EntityManager.SetComponentData(redSpawnEntity, redunitTransform);


                componentDataRed.hp = gameManager.HPRed;
                componentDataRed.attackDamage = gameManager.AttackRed;
                componentDataRed.attackRange = gameManager.AttackRangeRed;
                componentDataRed.attackSpeed = gameManager.AttackSpeedRed;
                componentDataRed.movementSpeed = gameManager.MovementSpeedRed;
                componentDataRed.unitNum = unitNumberAdd;
                unitNumberAdd++;
                state.EntityManager.SetComponentData(redSpawnEntity, componentDataRed);

            }


    }
}

if there is way i can access system from another mono object

If you want a system to trigger one on loading of a scene, create a GameObject in the subscene and bake it into an entity with a tag.
Require that tag component for the system to update. In the update of the system destroy the entity that has the tag components.

When you reload the scene the tag entity is loaded with it and the system will run again once