-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Add missing unsafe
to entity_command::insert_by_id
and make it more configurable
#18052
Add missing unsafe
to entity_command::insert_by_id
and make it more configurable
#18052
Conversation
pub unsafe fn insert_by_id<T: Send + 'static>( | ||
component_id: ComponentId, | ||
value: T, | ||
mode: InsertMode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere the pub
methods seem to use insert
for InsertMode::Replace
and insert_if_new
for InsertMode::Keep
. Should we add insert_by_id_if_new
instead of adding a mode
parameter, for consistency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sort of already inconsistent, since entity_command::insert_from_world
and command::insert_batch
have a parameter instead of another method. I wouldn't really mind either way, but that sort of combinatorial API explosion can be contentious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I do prefer the parameter approach to avoid the combinatorial API explosion, I just also like consistency :).
Would it be worth creating a follow-up issue to remove insert_if_new
in favor of an InsertMode
parameter on insert
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I briefly did that as part of this PR before I changed my mind lol. I could re-add that here, or make another PR if you think it's a big enough change or too unrelated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if we even wanted to change the already-released EntityCommands::insert_if_new
, and we wouldn't want to block a soundness fix with a debate about that. The functions in this file are new in this release, though, so if you're just changing these then I'm happy either way!
Objective
insert_by_id
is unsafe, but I forgot to add that to the manually-queueable version inentity_command
.It also can only insert using
InsertMode::Replace
, when it could easily be configurable by threading anInsertMode
parameter to the finalBundleInserter::insert
call.Solution
unsafe
and safety comment.InsertMode
parameter toentity_command::insert_by_id
,EntityWorldMut::insert_by_id_with_caller
, andEntityWorldMut::insert_dynamic_bundle
.InsertMode
parameter toentity_command::insert
and removeentity_command::insert_if_new
, for consistency with the other manually-queued insertion commands.