- Home /
Zenject factory from prefab not injecting into all components on prefab
I have a prefab "PlayerCharacterPrefab" with two components: PlayerCharacter
and CharacterMovement
. I am using zenject to bind a factory to produce PlayerCharacter
s from the "PlayerCharacterPrefab":
Container.BindFactory<PlayerCharacter, Factory<PlayerCharacter>>().FromPrefab(_playerCharacterPrefab);
I have another MonoBehaviour that wants to create "PlayerCharacterPrefab"s at will. It looks something like this:
public class PlayerCreator : MonoBehaviour
{
[Inject]
private Factory<PlayerCharacter> _playerCharacterFactory;
void Update()
{
_playerCharacterFactory.Create();
}
}
All of this works well, except for one problem. Both the CharacterMovement
and PlayerCharacter
components have dependencies which need to be injected. However, the factory is only injecting dependencies for the PlayerCharacter
component when it instantiates the "PlayerCharacterPrefab".
My expectation is that the factory would inject dependencies for all components on the prefab. What am I doing wrong?
I just tried this same thing and confirmed that it works as expected (that is, both Character$$anonymous$$ovement and PlayerCharacter get injected). Can you post the code for Character$$anonymous$$ovement and PlayerCharacter? How are they being injected?
Sorry for late reply, I didn't get any alert that there was a new comment on my question. I just took a closer look in light of the fact that you couldn't reproduce the issue and I think my description of the issue I'm seeing to mistaken. I might edit the question, or remove if it turns out I was completely mistaken. Thanks for taking the time to try and reproduce my problem.