How to spawn prefabs with scene graph from editable array

You don’t generate an entity_prefab by itself. You’ll want to make a new prefab type in your content browser. After you do that, Assets.digest.verse will generate a new entry for your prefab like this:

Prefab_my_prefab<scoped {/yourname@fortnite.com/yourproject}> := class<final>(entity):

In your other code you can spawn this via:

ThisPrefab : entity =  Prefabs.Prefab_my_prefab{} # "Prefabs." if thats the name of the folder you created your prefab definition in.

At this point the prefab object exists but is not in the scene. You need to add it to an entity. You can either add it to the Simulation Entity or any other entity if you want to nest it. You just use this API on the entity you want to add it to:

    @experimental
    # Adds the provided entities as children of this entity.
    #   * If child entity already has a parent, removes the entity from its current parent and adds it to the new one.
    #   * Added child entities will move through their lifetime methods until they match the state of the new parent.
    AddEntities<native><final><public>(NewChildEntities:[]entity):void

Note that it takes in an array. If you’re only adding a single entity/prefab you’ll need to wrap an array{} around it.

1 Like