-
Notifications
You must be signed in to change notification settings - Fork 362
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
FromComponentInParent injection fails when component is inactive #275
Comments
Running into the same issue. I couldn't figure out why |
The reason that it's inactive during injection is because we have to do it that way to ensure that injection happens before awake. It's tempting to change it to have includeInactive set to true as the default, but then that would be the opposite of what unity does with GetComponentsInChildren. It's not a great situation but not sure how to address. For now I think you just have to pass includeInactive as true every time you use the FromComponentX methods to ensure it works for prefabs. @taylank added it for FromComponentInParents already |
I changed my mind about it. Having includeInactive set to false as a default makes this behaviour happen frequently for new users. So I've change the default to true in zenject 6 even though it's possible that will break things for some people upgrading. I think this issue is common enough to justify it. It is the opposite default of unity's GetComponentX methods, but makes more sense to both address this issue and also just in general. We already inject into all inactive components, so kind of makes sense to also resolve inactive components via the FromComponentX methods by default as well |
…reasons discussed in issue modesttree#275
I noticed that when I instantiate a new prefab with the IInstantiator.InstantiatePrefabResourceForComponent method using a custom factory, the prefab instance generated starts out as inactive. Because of that, any members on the children of the prefab using FromComponentInParent binding for injection tend to fail.
var res = ((MonoBehaviour)ctx.ObjectInstance).GetComponentsInParent<TContract>() .Where(x => !ReferenceEquals(x, ctx.ObjectInstance));
MonoBehaviour.GetComponentsInParent ignores inactive behaviours by default, although this can be avoided with the (bool includeInactive = true) flag.
Setting that flag to true makes things work just fine for me, but I was wondering if the current behaviour of that zenject binding is deliberate, and if yes, what the reasoning is.
The text was updated successfully, but these errors were encountered: