Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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:
    74
    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.