-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Workflow for working with prefab entities #1446
Comments
In order to turn a created entity into a bundle again, we can borrow from the approach taken in |
Something to consider is how this would interact with #1442. |
I believe that scenes are the intended solution for that, what feature are they missing? |
That's what I tried initially, but when you spawn a scene, there is no way to edit components on the entity, or even to know what entity was spawned. Scenes are spawned through SceneSpawner::spawn_dynamic. For example, there is no way to spawn a scene at a specific location, which is a common thing to do with prefabs. |
You can do the following:
Step 3 definitely needs a better API, but it's already possible. How would you want to do it? How about a method to get an entity from its name, and a component from its type? Aside from that, there are still some issues when spawning a deserialized scene. I'm working on it in #1395 but it's waiting for review. |
Actually, it seems it would be easier to use |
I am loading my prefabs from a JSON file and then converting each one into a dynamic scene at runtime. I am doing this because Bevy does not have an editor, so I use an editor to set up my entities and then save it as JSON. Is it possible to do this with a Scene instead of DynamicScene? I think the idea is that prefabs always have a root entity. In Unity they do at least. Not sure about Godot. Would it be worth it to have a special type of scene for prefabs, that are always guaranteed to have a single root entity? Then you won't have to get the entity by name at least. |
Also, would that workflow work if you wanted to spawn hundreds of copies of a prefab? It seems like you'd have to make hundreds of scenes (so that you can modify the Transform on each one), and then spawn a single entity from each one. I could be wrong but it doesn't sound efficient. |
You can convert a
You can use the
The scene is not changed when you spawn it, its entities are just copied into the app's |
I don't understand why I think there should be a way to do this without using an exclusive system though. It would be best to be able to do all of this with Edit: I just wanted to confirm that using |
Closing in favor of #3887. |
What problem does this solve or what need does it fill?
Prefabs allow users to rapidly add copies of predefined entities to their game, and create variations on them.
What solution would you like?
The basic workflow would be:
World
either using its own systems, directly from code or by reading in a serialized format.State
on_enter systems?) to finish initializing the entity in the main game world.There are a few things we'd need to have this work:
Worlds
..spawn(cloned_entity_bundle).with(modified_component)
, but it would need to be clear that.with
is overwriting.What alternative(s) have you considered?
Use component bundles with the struct-update Default pattern used in e.g.
SpriteBundle
.This works quite well for statically defined prefabs, which can each get their own type. I'm not sure it works correctly (or naturally) for prefabs that are created dynamically or loaded from a serialized format. You would need to create new Bundles at runtime, which I'm not sure you could do.
The functionality needed all seems useful for other purposes though, and the pattern seems quite natural, so it may still be worthing pushing users towards it even if those barriers can be overcome.
Additional context
This issue ties into discussion in #255, although it doesn't actually use
Scenes
to accomplish its goals.This issue was prompted by this conversation on Discord.
Multiple interacting
Worlds
was mentioned in #1343 for decoupling graphics and physics.The text was updated successfully, but these errors were encountered: