EntityCloner
has no concept of required components after configuration which may have surprising effects depending on the target archetype
#19324
Labels
Uh oh!
There was an error while loading. Please reload this page.
Bevy version
0.16
What you did
What went wrong
The assertion fails, the target now contains
Required(20)
.This is surprising, since I did not explicitly ask for that to be cloned and it should not happen if the target already contains it.
The issue here is that
EntityCloner
has no information of the target entity at the time of configuration. You can either tell it to moveExplicit
with or withoutRequired
, the latter by usingEntityCloner::without_required_components
. This is not comfortable because you would have to check the target archetype first to pick the correct configuration. There is no automatism.To make the issue more clear, these are the possible scenarios if I wanted to clone
Explicit
with or withoutRequired
:without_required_components
Explicit(10)
,Required(10)
Explicit(20)
,Required(20)
❌Required(10)
Explicit(20)
,Required(20)
❌Explicit(20)
,Required(20)
✅Explicit(10)
,Required(10)
Explicit(20)
,Required(10)
✅Required(10)
Explicit(20)
,Required(10)
✅Explicit(20)
,Required(0)
❌As you can see, if you only want to clone
Required
if it does not exist at the target yet, likeinsert
behaves where it only constructs a defaultRequired
when needed, you need to check the target archetype first and pick the correct cloner configuration based on that.This makes this API uncomfortable.
A proper fix, if we want to keep
EntityCloner
agnostic to the target archetype (since it may be used on multiple source/target pairs as I saw in the code), it should at least know whichComponentId
were given as explicit or implicit.The text was updated successfully, but these errors were encountered: