I’m switching a procedural generation system to Scene Graph but am wondering how I can assign prefabs to editable arrays. For example, in the past i had an array of creative_prop_asset that I could assign on the device in editor and would SpawnProp on them. What is the equivalent of creative_prop_asset in Scene Graph? I tried entity_prefab but it says that class should only be used in generated digests. entity_prefab also has no way to be spawned.
EDIT: I also tried storing just meshes with Verse.Assets and then making mesh_components, but I am unable to construct mesh_components with a certain mesh as of now. Seems like although scene graph is powerful, SpawnProp and prop assets still might be the way to go for procedural generation, unless anyone else has additional info.
Kind of a stupid suggestion I tried just making a entity editable it seemed to semi work in editor atleast
with this code
it generated a device that had values but pressing on them as a list was empty
And weirdly enough If I directly copied the values I could “paste” them in different options eg I managed to switch TheEntity1 and TheEntity2
That being said I doubt this is intended behavior
Ok yea it seems like declaring them by name in the script works, my problem is I have a library of biomes that each have an array of their tiles so quickly I get to around 50 different tiles, so writing them all out by name is a lil much. Hearing about scene graph I thought it would make my workflow easier but for now I think I’ll stick to SpawnProp unless they add a way to spawn entity prefabs.
I also tried having a blank entity prefab and adding entities with mesh components to them because I can store editable arrays of meshes, but it seems like you can’t construct mesh_components in creative_devices, just components.
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.
Yeah I just have about 50 tiles right now that will grow to at least double when I add more biomes so writing them all in the script by name does not seem worth it
Fair, I suppose a workaround would be to just also make your Biomes as Enums and have a function that takes the Enums and returns an entity. This way you can easily “differentiate” the different entities inside your editor. Just so long as you remember to update the big main Enum to Entity function with your new prefabs
PrefabEnums:=enum{GrassPrefab,RockPreFab}
game_manager:=class(creative_device):
@editable MyEntity:PrefabEnums = PrefabEnums.GrassPrefab
OnBegin<override>()<suspends>:void=
if(RootEntity:=GetSimulationEntity[]):
RootEntity.AddEntities(array. EnumToEntity(MyEntity))
EnumToEntity(MyEnum:PrefabEnums):entity=
case(MyEnum):
PrefabEnums.GrassPrefab=>Prefab_new_entity{}
PrefabEnums.RockPreFab=>Prefab_new_entity1{}
hmm yeah this is getting closer, hopefully they can just add a SpawnPrefab function eventually haha
Couldn’t you just make your own SpawnPrefab function?
SpawnPrefab(Entity:entity,Coordinates:(/Verse.org/SpatialMath:)transform):void=
if(RootEntity:=GetSimulationEntity[]):
RootEntity.AddEntities(array. Entity)
Entity.SetGlobalTransform(Coordinates)
or something like this that creates a new entity when SpawnPrefab is run
SpawnPrefab(PrefabType:PrefabEnums,Coordinates:(/Verse.org/SpatialMath:)transform):void=
Entity:=EnumToEntity(PrefabType)
if(RootEntity:=GetSimulationEntity[]):
RootEntity.AddEntities(array. Entity)
Entity.SetGlobalTransform(Coordinates)
Obviously a function already implemented in the digest would be more useful though
Yeah but then I get back to my original problem that I can’t have easily editable arrays to pull from and would have to write each prefab out by name
Unfortunately yea but you would only have to do that ONCE when you generate that prefab and won’t have to hand write it each time you want to use it. You write it once on the Main EnumToEntity function and then you can use them infinitely, Just have to I guess write those 50 prefabs once and then you should be clear
Yea its basically writing my own digest file by hand, maybe I can make a script for that. I’m still debating sticking with props for the world building because the workflow is easier, but I’m definitely gonna be using scene graph for interactables because right now I have a pool of buttons that I teleport to where they’re needed haha