Skip to content

Conversation

martindevans
Copy link
Contributor

As briefly discussed in Discord, this modifies the CommandBuffer to not return fake Entity objects. Instead it returns a PendingEntity. This makes the API less confusing and prevents all the mistakes you could make.

Added a new test ("CommandBufferEntityErrors") which demonstrates all the possible errors this fixes:

  • Using the returned Entity with the world (fails type checking)
  • Creating an entity with one buffer, using it with another buffer (throws)
  • Creating an entity, calling playback, then trying to use the entity with this buffer (throws).

Breaking Change

Note that this is a breaking change: The Create() -> Entity method has become Create() -> PendingEntity.

Most code that is broken by this should either be extremely easy to fix (just change the type) or was already subtly broken and this more explicit break is a good thing.

…his prevents using the returned `Entity` in incorrect parts of the API.
@martindevans
Copy link
Contributor Author

martindevans commented Oct 27, 2023

To be honest I don't really like the name PendingEntity, but couldn't think of anything better.

@genaray
Copy link
Owner

genaray commented Oct 30, 2023

Thanks! Im gonna look at that one later ^^
Just wonder if there any drawbacks to this. E.g. having an PendingEntity might be a bit restrictive in certain scenarios. Im gonna check that

@martindevans
Copy link
Contributor Author

I don't think there's anything that is valid to do with the "Entity" returned by the CommandBuffer that the PendingEntity doesn't allow. If you do identify something a use-case I've missed I'll add something to support it.

@Shelim
Copy link

Shelim commented Aug 1, 2025

Bumping the PR - it would make desired usage of value returned from CommandBuffer so much cleaner and much less prone to human errors. Even the docs currently does not specify what is allowed with returned value and - for me example - it was easy to (wrongly) believe I can use the value as standard entity identifier after executing all commands from the buffer.

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

Successfully merging this pull request may close these issues.

3 participants