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

[Question] Injection on instantiated Scriptable Object from Game Object Context Installer #80

Open
ATHellboy opened this issue Sep 9, 2023 · 1 comment

Comments

@ATHellboy
Copy link

Hey guys, I'm stuck on something about Zenject/Extenject. Any one has any idea how I can fix that ?
btw, sorry for filing an issue here, I can't get my answer from anywhere.

I have Player gameObject with Game Object Context which instantiate Character prefab by factory and Charcater has Game Object Context. In CharacterController which is a facade class on Character I instantiate a few Scriptable Objects in this way:

private readonly DiContainer _container;

public ZenjectResourceFactory(DiContainer container)
{
    _container = container;
}
public Object Instantiate(Object @object)
{
    Object instance = Object.Instantiate(@object);
    _container.QueueForInject(instance);
    return instance;
}

In the Character Installer CharacterBehavior and CharacterPowerup are bound by Container.Bind<CharacterBehaviorContext>().AsSingle().NonLazy(); and Container.Bind<CharacterPowerupContext>().AsSingle().NonLazy();

But the issue is CharacterBehavior and CharacterPowerup are not injected into those Scriptable Objects [Inject] methods.

@L1247
Copy link

L1247 commented Oct 23, 2023

you need to use Bind instead of Instantiate then container will inject Scriptable Objects automatically.

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