-
Notifications
You must be signed in to change notification settings - Fork 566
Weak Entity Reference #6245
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
base: master
Are you sure you want to change the base?
Weak Entity Reference #6245
Conversation
| internal readonly int Id = uid.Id; | ||
|
|
||
| /// <summary> | ||
| /// The underlying entity this reference is pointing to. | ||
| /// You should not be accessing this directly! | ||
| /// </summary> | ||
| internal EntityUid Entity => new(Id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to just have these be private members and then have the TryGetEntity function be on the struct. I think being internal is a good compromise that at least prevents content from accessing the entityUid directly.
| await server.WaitAssertion(() => | ||
| { | ||
| var entA = sEntMan.GetEntity(netEntA); | ||
| var comp = sEntMan.GetComponent<WeakEntityReferenceTestComponent>(entA); | ||
| var entB = sEntMan.GetEntity(netEntB); | ||
| sEntMan.DeleteEntity(entB); | ||
| sEntMan.Dirty(entA, comp); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if this actually checks if nothing caused errors on the client or server. If there's a better way to do this, let me know.
|
Got around to fixing the tests and adding in some missing API stuff (ToPrettyString, resolves, etc.) Should be good to go now |
PJB3005
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do WeakEntityReferences still have a concept of invalid? Especially in the serialization code, from my reading, deserialization of a broken weak entity reference would cause an error.
Invalid is just meant to serve as the default/uninitialized state of the
I've added proper reading for invalid values now. I must've missed it, since the values were properly validated in other parts of the serialization. Also as an aside I think the github tests exploded for some unrelated reason to the PR. |
|
I was interested in this as a comparison so I compared this to Unreal Engine's concept of a TWeakRef, and there their default state is to wrap a nullptr of type I took a look and I do think that Thoughts? Happy to be wrong here. |
The |
|
That is true, thanks for the response. |
Basic weak entity reference implementation based on ElectroSr and Tayrtahn's implementation from #5577 combined with PJB's review from #6114
Apologies for not preserving git history as my PR process was a bit scattershot and not exactly the cleanest. The majority of this PR is the work of others which I've done my best to correct according to review and my own beliefs.
Weak Entity Reference is simply an EntityUid wrapper that requires the TryGetEntity function to be used to get the contained entity. The check ensures that the referenced entity always exists, hopefully preventing content errors due to deleted references. Additionally, the struct networks as invalid if the referenced entity is no longer valid, preventing errors from attempting to get the metadata component.