-
Notifications
You must be signed in to change notification settings - Fork 124
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 object-oriented EntityId
methods
#725
Comments
This is something we've discussed a fair bit, but my opinion remains that we should not do this because it implies the object referred to the ID always exists, which isn't the case - that is, during that sequence of calls, I think the form in which we're most likely to see this is #406, in which we can guarantee that an entity exists while we operate on it, which allows us to offer a richer API. Another idea is reference-counted entities where having an id to them keeps them alive, but I'm not sure if that will happen any time soon, either. |
Right now, guest-side code is single-threaded, so it's impossible for entities to be despawned while a guest is working with them unless the guest despawns them itself. We can help mitigate the ambiguity of whether entities are alive or not by making No, this will not solve issues of questionable ID validity, but as it stands, the Adding a guard to make sure that entities are alive is as simple as this: if !entity::exists(e) {
return;
} But I think that it's a lot more conducive to habitual error checking if it's as simple as this, instead: if !e.exists() {
return;
} |
You can have multiple let id = Entity::new().spawn();
run_async(async {
sleep(5.0).await;
id.set(blah(), 5); // `id` could have been despawned in the meantime
}); There's also the possibility that we expose multiple ECS worlds to the guest (#230 maybe?), so that you need to have a reference to the world in order to do anything. This would fairly easily generalise from our existing API - the functions would end up being methods on a world handle - but it ends up being more unclear if we move the methods to the ID. For reference, here's the discussion we had about this on the Discord that led to #406: https://discord.com/channels/894505972289134632/1078283561540530216/1108329570916118609 I would like to offer a sleeker API - for the same reasons you mention - but I'm also afraid of implying that the IDs represent the entity, instead of merely pointing to one. I've seen people struggle with the distinction between entity handles and entities before, as well as entity lifetimes, so I want to make it as obvious as possible, even if it comes at a bit of an ergonomics cost. That being said, one change that I'm not opposed to and that we should probably consider is to rename the methods to make them less verbose (i.e. drop the I'm also not that opposed to adding |
As game codebases scale, I begin to find this extremely noisy and hard to read:
I think that a much more readable (and idiomatic if you're looking at Ambient packages as objects) alternative is this:
This would apply for all other functions on
EntityId
in theentity
module such ashas_component()
.The text was updated successfully, but these errors were encountered: