1

Installer:

class MainInstaller : MonoInstaller<MainInstaller>
{
    [SerializeField]
    private StateController StateController;

    public override void InstallBindings()
    {
        Container.BindInstance( StateController );
    }
}

Behaviour with injection:

class Foo : MonoBehaviour
{
    [Inject]
    private StateController StateController;

    void Start()
    {
        UpdateObject( StateController.Current );
    }
}

Problem is StateController is null at UpdateObject.

Should I instantiate gameobject somehow especially?

Galandil
  • 4,169
  • 1
  • 13
  • 24
A. Akzhigitov
  • 179
  • 2
  • 14

1 Answers1

1

Here is the answer https://github.com/modesttree/Zenject/issues/57.

GameObject.Instantiate does not resolve dependencies. One should use DiContainer.InstantiatePrefab or use Factories.

A. Akzhigitov
  • 179
  • 2
  • 14