1

I use Factories to create GameObjects from prefabs.

MenuScreen (prefab root game object)
  * MenuScreenComponent <- inject ScreensNavigator
  - Button (game object)
    * ButtonSoundBehaviour <- inject AssetsProvider

In the installer:

Container.BindFactory<MenuScreen, MenuScreen.Factory>().FromComponentInNewPrefab(MenuFragmentPrefab);

ScreensNavigator injected into MenuScreenComponent without any problems.

How to make ButtonSoundBehaviour to be injected with AssetsProvider? I tried to add Zenject Binding to Button GameObject but it doesn't help.

Alexandr
  • 3,859
  • 5
  • 32
  • 56

1 Answers1

1

You need to tell zenject where to find AssetsProvider by adding a binding for it on the container.

For example, if you add Container.Bind<AssetsProvider>().AsSingle() to an installer, then ButtonSoundBehaviour will have AssetsProvider injected into it.

Steve Vermeulen
  • 1,406
  • 1
  • 19
  • 25