Search Unity

Bug Trying to access product container before it is initialized.

Discussion in 'Visual Scripting' started by AnsisMalins, May 3, 2022.

  1. AnsisMalins

    AnsisMalins

    Joined:
    Mar 16, 2014
    Posts:
    30
    I check out my project on another computer, and visual scripting does not work, and editor spams the following in the console. What to do?

    InvalidOperationException: Trying to access product container before it is initialized.
    Unity.VisualScripting.ProductContainer.EnsureInitialized () (at Packages/com.unity.visualscripting/Editor/VisualScripting.Core/Products/ProductContainer.cs:96)
    Unity.VisualScripting.ProductContainer.GetProduct (System.String productId) (at Packages/com.unity.visualscripting/Editor/VisualScripting.Core/Products/ProductContainer.cs:121)
    Unity.VisualScripting.EditorPreferencesProviderView.OnGUI (System.String searchContext) (at Packages/com.unity.visualscripting/Editor/SettingsProvider/EditorPreferencesProviderView.cs:40)
    UnityEditor.SettingsWindow.DrawControls () (at <780782bc035845f9909cebbd4c983ae3>:0)
    UnityEditor.SettingsWindow.DrawSettingsPanel () (at <780782bc035845f9909cebbd4c983ae3>:0)
    UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.IMGUIContainer.DoIMGUIRepaint () (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.UIR.RenderChainCommand.ExecuteNonDrawMesh (UnityEngine.UIElements.UIR.DrawParams drawParams, System.Single pixelsPerPoint, System.Exception& immediateException) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    Rethrow as ImmediateModeException
    UnityEngine.UIElements.UIR.RenderChain.Render () (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.UIRRepaintUpdater.Update () (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.Panel.UpdateForRepaint () (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <f23cc42ed8af4b73afc7c74ab921aa08>:0)
    UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <f0d008a86f5e41eda07a8cec48955104>:0)
     
  2. AnsisMalins

    AnsisMalins

    Joined:
    Mar 16, 2014
    Posts:
    30
    The root cause was that Visual Scripting keeps track of its own location by searching for an asset GUID of a folder, but I don't track those in source control because so far they've only made deleting directories harder. Still, error spam is never okay.

    For myself, I fixed it like this:
    Code (CSharp):
    1. // It's okay to cache this because moving the Visual Scripting package around will
    2. // cause a domain reload which means the variable will be reset.
    3. private static string _packageRootPath;
    4.  
    5. public static string GetPackageRootPath()
    6. {
    7.     if (_packageRootPath == null)
    8.     {
    9.         // We don't store meta files of folders in source control, so we can't search by GUID.
    10.         string packageEditorAssetPath = AssetDatabase.GetAllAssetPaths()
    11.             .FirstOrDefault(i => i.EndsWith("/com.unity.visualscripting/Editor", StringComparison.OrdinalIgnoreCase));
    12.  
    13.         if (packageEditorAssetPath == null)
    14.             throw new FileNotFoundException($"Couldn't find Visual Scripting package folder.");
    15.  
    16.         // The root VS folder path is 1 directories up from our Editor folder
    17.         _packageRootPath = Path.GetDirectoryName(packageEditorAssetPath);
    18.     }
    19.  
    20.     return _packageRootPath;
    21. }