-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Make the NULL semantics of entity clear #16204
Comments
I prefer Entity::NULL over Entity::PLACEHOLDER, but would prefer to remove it entirely, or at least from the public API. Null-checking for data types is unidiomatic and frustrating. |
I'd be strongly against this & prefer the exact opposite.
The existence of There's nothing unidiomatic about this. It's just the meaning of |
I totally agree with that. Consider that with If the Entity were some form of smart pointer that conveys actual information about the world, I agree that having a NULL value would be incorrect. But since the Entity itself does not guarantee anything, that Option wrapper gives us nothing besides more useless code to write.
As a developer, I really do want to have some form of a default Entity that I can use. If you would want really hard to have Option anyway, then make it transparent to the users, like Entity itself being the wrapper: As that, I would even keep it as Entity::PLACEHOLDER since I like that name better than NULL. NULL suggests something missing/invalid, while PLACEHOLDER is a valid Entity, just one that is guaranteed to never be spawned in the world, so you can safely use it as an temporary intermediary value and it will error if you ever query for it(as would any non-existing Entity). We already have all we need, just this 2 things would make it perfect:
Perfection achieved : d |
I thought that cart said something about how he would prefer making it unnecessary to have PLACEHOLDER or None by improving the semantics of the ECS. Sorry if I'm misremembering. |
If he did I'm pretty sure it's with the same notions I've highlighted that I take issue with. |
What problem does this solve or what need does it fill?
Previously I mentioned this in discussions as "introducing" null semantics to
Entity
to not have to work withOption<Entity>
. This was incorrect.Entity
has always had null semantics but they are just hidden by the use ofOption
& misguides users.People have encouraged the use of
Option<Entity>
to store entity IDs & have the notion that theOption
beingSome
means you have a validEntity
ID. This is not correct. Even if you have anEntity
id it is not guaranteed to be valid. It mightn't be in your query, may have been despawned or with future features might be disabled.Option
isn't guaranteeing the entity exists it's only guaranteeing the ID existed on the other side of some API contract when it was produced. "Existed" is past tense meaning even if it isSome
correctness concerned users should still be using fallible APIs to check their entities because if you've only checked theOption
you've checked nothing. The use ofOption
isn't just redundant it can also misguide users who are new to bevy to think the following code should not panic:What solution would you like?
Replace
Entity::PLACEHOLDER
withEntity::NULL
& make it so no entity can have this id.Additional context
This change would not mean that people have to check
e != Entity::NULL
because fallible APIs exist onQuery
,World
etc. In practice having anEntity::NULL
is the same as having an ID of an entity that exists that you can't do anything with. It doesn't stop people from usingOption
either.The text was updated successfully, but these errors were encountered: