Skip to content
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

Entity.Null.IsAlive() throws instead of returns false #52

Closed
RoyAwesome opened this issue Jan 15, 2023 · 3 comments
Closed

Entity.Null.IsAlive() throws instead of returns false #52

RoyAwesome opened this issue Jan 15, 2023 · 3 comments

Comments

@RoyAwesome
Copy link

This surprised me. It threw an index out of range exception, which I would have expected to just return false.

@genaray
Copy link
Owner

genaray commented Jan 15, 2023

However, this makes sense... a null entity does not exist. Thus no entity operation can be performed on it. It should only be used for comparison purposes.

Imagine you call an operation on a null class ^^ This is correct behavior in this case.

@RoyAwesome
Copy link
Author

What would be the intended way of checking if an entity even exists before trying to do operations on it then?

@genaray
Copy link
Owner

genaray commented Jan 15, 2023

What would be the intended way of checking if an entity even exists before trying to do operations on it then?

var entity = world.Create(...);
if(entity.IsAlive())
   entity.Set(...);

Entity.Null is just for comparison, it acts as a null pointer while .IsAlive checks if its alive in its world :

if(myEntity != Entity.Null && myEntity.IsAlive())
   myEntity.Set(...);

Ahhh i see what the real problem here is. I will adjust the API so it is clearer. To check if an entity exists you currently have to call both to verify, I will change that.

@genaray genaray closed this as completed Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants