From 90451c5c4ab8d11fdccc25c409a33f664a0fd1c3 Mon Sep 17 00:00:00 2001 From: Adam Kapos Date: Tue, 21 Jan 2025 23:23:17 +0200 Subject: [PATCH 1/2] Don't construct object graph string while validating without issues --- .../SubContainerCreators/SubContainerCreatorCached.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Providers/SubContainerCreators/SubContainerCreatorCached.cs b/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Providers/SubContainerCreators/SubContainerCreatorCached.cs index b099aae78..c354c35b5 100644 --- a/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Providers/SubContainerCreators/SubContainerCreatorCached.cs +++ b/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Providers/SubContainerCreators/SubContainerCreatorCached.cs @@ -34,8 +34,10 @@ public DiContainer CreateSubContainer(List args, InjectContext co if (_subContainer == null) { #if !ZEN_MULTITHREADING - Assert.That(!_isLookingUp, - "Found unresolvable circular dependency when looking up sub container! Object graph:\n {0}", context.GetObjectGraphString()); + if (this._isLookingUp) + { + Assert.That(false, "Found unresolvable circular dependency when looking up sub container! Object graph:\n {0}", context.GetObjectGraphString()); + } _isLookingUp = true; #endif @@ -48,7 +50,7 @@ public DiContainer CreateSubContainer(List args, InjectContext co Assert.IsNotNull(_subContainer); } - else + else { injectAction = null; } From 671a4ed49e11acef3af91b4b6515e3397cb10fcb Mon Sep 17 00:00:00 2001 From: Adam Kapos Date: Tue, 21 Jan 2025 23:23:46 +0200 Subject: [PATCH 2/2] Print meaningful object graph for Unity components --- .../Source/Runtime/Injection/InjectContext.cs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Injection/InjectContext.cs b/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Injection/InjectContext.cs index 86d13be60..2825a201b 100644 --- a/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Injection/InjectContext.cs +++ b/UnityProject/Assets/Plugins/Zenject/Source/Runtime/Injection/InjectContext.cs @@ -268,6 +268,28 @@ public string GetObjectGraphString() result.AppendLine(context.ObjectType.PrettyName()); } +#if !NOT_UNITY3D + if (this.ObjectInstance is UnityEngine.Component component) + { + // Print the GameObject hierarchy + var transform = component.transform; + while (transform != null) + { + if (transform.name.EndsWith("(Clone)")) + { + // Stop printing when we find an instantiated object, we are validating that prefab + result.AppendLine(transform.name.Replace("(Clone)", " (prefab)")); + break; + } + else + { + result.AppendLine(transform.name); + transform = transform.parent; + } + } + } +#endif + return result.ToString(); } }