-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Making Required Components force existence as a follow-up of #18514 #18566
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
Comments
@cart is on the fence about this, but I think that this makes sense as one of a few related variants on the concept. |
Coming from #18514, I actually like this solution generally better from a DX perspective. But here's a few things to think about. First, I'd like to see inverses. Not just Second, I'm not sure about baking this into the syntax of Third, I don't think a silent fail with Finally, I think we should implement this very generally. Just like spawning has affects (and more planned), I think we should make this similarly extendable (even though it's not planned yet). And I think we can implement some of this at the |
I think it can be a good idea not to bake removal into required syntax and add
In this (I think a pretty rare) case, for example, unloading a I personally think that doing this by default is a strange and misleading behaviour, when something tries to remove a component and it suddenly has somewhat corrupted data. Additionally, maybe trying to remove a required component should produce a warning or error.
I think I agree with this. |
I agree that it's rare. But having the user do
I agree here too, but all of this is "strange and misleading". It is misleading that
100% agree here. This should tap into the new error handling somehow. I think making |
I agree with your points, with them considered my opinion is strongly on making Also, you brought up an interesting thing:
This is a source of misleading behaviour and even bugs, maybe. It should be thought through carefully. It is somewhat like Rust's orphans rule prevents, by the way. |
Yeah, I agree. We're on the same page; it's just tricky lol. |
Before we return an error here, I want to solve #17273. |
I'm thinking about this more, and I think this is really just a special case of #1481 (archetype invariants). It's just that we want to register these invariants when we register required components. I think we should probably tackle (incrementally) #1481 and then come back to make required components trigger this behavior. I do still think |
What problem does this solve or what need does it fill?
The #18514 proposes a way to enforce the invariant of existence of required components.
While the following opinion can be controversial, I believe that this invariant should be held by default - as even the wording of Required Components means that the specified component is required for correct behaviour of the component it is specified for.
As for justification of having the API to enforce such a variant - see #18514, it is described there wonderfully that this both improves DX and can improve performance by removing unnecessary checks.
I propose that the behaviour of
(states that when
A
is present,B
can not be removed) should be the default behaviour of required components, and that(states that when
B
is removed,A
is also removed) and the current behaviour of allowing to remove the required component afterwards should be options on the required component.What solution would you like?
#[require(B)]
andworld.register_required_components
now also apply the logic of#[removal(stops(B)]
by default.world.register_required_components
for specifying the behaviour of removal tracking.#[require(B)]
, you should write#[removal(when(B)]
on#[require(B)]
, you should writeWhat alternative(s) have you considered?
Do not change the behaviour, so in most cases the developer would write either (most of the time)
or like now (second place of commonness) to allow removal
or (in I think very rare cases)
I personally think this is a worse DX than changing the behaviour of required components.
Additional context
Unity has the notion of required components in its EC architecture, and it prevents the removal of the required component both in Editor and in Playmode both from Editor UI and from scripts with the error
Can't remove *B* because *A* depends on it
.The text was updated successfully, but these errors were encountered: