Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Spawning entity from monobehaviour.

Discussion in 'Entity Component System' started by Unique-Player, Dec 5, 2022.

  1. Unique-Player

    Unique-Player

    Joined:
    May 6, 2017
    Posts:
    42
    Is it possible to call a method inside the BaseSystem or ISystem to spawn entity from monobehaviour script?
    The only idea i have is to create buffer list to add units for spawn, and check in system`s on update if list contains units to spawn.
    What is the right approach?
     
  2. Salmakis

    Salmakis

    Joined:
    May 14, 2018
    Posts:
    15
    you can just grab the EntityManager from the world in your monobehavior.

    Code (CSharp):
    1. var entityManager  = World.DefaultGameObjectInjectionWorld.EntityManager;
    and then just use it like you where in a system.
    if you spawn some here and then it should be no problem for the performance.

    depending on your setup you might need another world :)
     
    Unique-Player likes this.