Open yellowisher opened 2 months ago
public static GameObject InstantiateAndInject([NotNull] this IObjectResolver resolver, [NotNull] GameObject prefab, Transform parent = null)
{
if (prefab == null)
throw new NullReferenceException(nameof(prefab));
bool prefabWasActive = prefab.activeSelf;
prefab.SetActive(false);
GameObject instance = resolver.Instantiate(prefab, parent);
prefab.SetActive(prefabWasActive);
instance.SetActive(prefabWasActive);
return instance;
}
If I instantiate prefab with
IObjectResolver.Instantiate()
, the prefab show up in my VCS without any changes. Yes, when I stage them, they are gone but its pretty annoying.The reason is IObjectResolver.Instantiate() directly disable the prefab itself then Instantiate it. (maybe for calling
Inject
beforeAwake
?) Zenject Instantiate a prefab as a child of inactive GameObject rather than disable prefab itself. Link