Skip to content
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

Instantiating with null extra args ends with exception #48

Open
martin-obert opened this issue Aug 13, 2022 · 1 comment
Open

Instantiating with null extra args ends with exception #48

martin-obert opened this issue Aug 13, 2022 · 1 comment

Comments

@martin-obert
Copy link

martin-obert commented Aug 13, 2022

Once creating game object for component via IInstantiator, like:

_instantiator.InstantiateComponent<MyComponent>(_executor, new object[] { task = task, onSuccess = onSuccess // <-- this is null });

ends with error indebug:

ZenjectException: Assert hit! Cannot include null values when creating a zenject argument list because zenject has no way of deducing the type from a null value. If you want to allow null, use the Explicit form.

what does the If you want to allow null, use the Explicit form actually means? Cannot find any official docs on it.

@Monsoonexe
Copy link

Monsoonexe commented Aug 27, 2024

you need to pass a List manually, since Zenject can't determine the contract type of null (using GetType()). So you need to use the _instantiator.InstantiateComponentExplicit<MyComponent>() method instead. And instead of using new object[] { ... } you need to use the more verbose strategy var args = new List<TypeValuePair>() { new TypeValuePair(typeof(TypeOfYourNullThing), null) } ;

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

No branches or pull requests

2 participants