Generic Entity<T> and handling by-value events by-ref #21113
DrSmugleaf
announced in
Code announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
space-wizards/RobustToolbox#4498
Entity has been added, which is used to hold both an EntityUid and one or more components associated with it. It should be used to replace obsoleted usages of Component.Owner.
This changes how methods should accept and return parameters.
Before:
After:
This also helps prevent confusion when a method has more than one EntityUid parameter.
Content and engine methods will be updated to this new format.
If more than one component is needed, Entity<T1, T2, ...> can be used, for example
Entity<DoorComponent, PhysicsComponent>
orEntity<DoorComponent, PhysicsComponent, SpriteComponent>
would associate a single EntityUid with multiple components that it owns.Entity can accept up to 8 components.
Tuples of (EntityUid, T) are automatically converted into Entity.
Entity is implicitly converted into EntityUid and T, so you don't need to manually write ent.Owner and ent.Comp when passing it as a method argument.
Event subscriptions can handle events with Entity, and subscriptions in this style may only handle events by ref.
By-value events may now also be handled by-ref without resulting in an error. In the future handling events by-value instead of by-ref will be obsoleted.
All of these changes must be present in PRs made and opened after today's engine update. PRs currently open or in progress are not affected.
Beta Was this translation helpful? Give feedback.
All reactions