Rename observe to observe_entity on EntityWorldMut #15616
+52
−36
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
The current observers have some unfortunate footguns where you can end up confused about what is actually being observed. For apps you can chain observe like
app.observe(..).observe(..)
which works like you would expect, but if you try the same with world the firstobserve()
will return theEntityWorldMut
for the created observer, and the secondobserve()
will only observe on the observer entity. It took several hours for multiple people on discord to figure this out, which is not a great experience.Solution
Rename
observe
on entities toobserve_entity
. It's slightly more verbose when you know you have an entity, but it feels right to me that observers for specific things have more specific naming, and it prevents this issue completely.Another possible solution would be to unify
observe
onApp
andWorld
to have the same kind of return type, but I'm not sure exactly what that would look like.Testing
Simple name change, so only concern is docs really.
Migration Guide
The
observe()
method on entities has been renamed toobserve_entity()
to prevent confusion about what is being observed in some cases.