Search Unity

Spawn Refab Object using ECS

Discussion in 'Entity Component System' started by franky_U, Jun 25, 2019.

  1. franky_U

    franky_U

    Joined:
    Mar 13, 2019
    Posts:
    12
    Hi i am trying to instantiate a prefab from the project which has some componentData attached to it,
    What is the best way to instantiate a prefab without using any GameObject reference.
     
  2. daschatten

    daschatten

    Joined:
    Jul 16, 2015
    Posts:
    208
    You can use
    GameObjectConversionUtility.ConvertGameObjectHierarchy() to convert Gameobject Prefabs to Entity Prefabs (e.g. in
    OnCreateManager())
    and instantiate them with
    EntityCommandBuffer.Instantiate().
     
  3. franky_U

    franky_U

    Joined:
    Mar 13, 2019
    Posts:
    12
    @daschatten Thanks for your reply. So i have a prefab with hierarchy inside. so do i need to loop in through Gameobject prefab .or will this directly work.
     
  4. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    966
    It'll work directly.
    You can even put proxies in childs and it gets converted. Useful for moving/rotating parts.