Cannot make changes in Debugger

Hi,

I was under the impression that it would be possible to change values in the UIElements Debugger and see the changes reflected in the app, but that’s not happening. Hacking around with the values is a pretty core workflow in Chrome for web developers, and reading around, it sounds like the UIElements Debugger should also do it.

But I have no so far been able to change a single value and have anything look differently in the app. What am I missing?

Just to clarify, do you mean you are not seeing changes reflect in the Game View ? Or by app do you mean “in the app built from Unity running directly” ?

Hi,

This is in the Game view running in the editor. I was hoping to do like you do in Chrome, that you tweak parameters and get immediate feedback. This is especially useful since Unity’s default styles don’t ship with a stylesheet, and it can be difficult to understand where a particular styling effect is coming from, or even whether you’re barking up the right tree.

Of course, for styles you’re creating yourself from scratch, it’s not too much bother to just change the USS file and reload. So changes in a debugger are always about debugging. But no changes seem to cause a change in the Game view.

Ok, I think you are describing a bug we didn’t know about, e.g. UI Elements debugger does not cause a repaint of the GameView when not in Play mode.

Can you confirm your changes are reflected when entering playmode?

Hi,

This is making changes during Play mode. It’s not really possible to make these changes in non-play mode, since the UI I’m editing is contextual.

I have no problem editing USS files while in Play mode and seeing the changes reflected in the running UI immediately when switching back to Unity.

Ok that is surprising. Sorry for asking so many clarifications but since the UI Debugger has no documentation to speak of I want to make sure I understand your issue. Are you saying the USS rules shown in the “Matching selectors” aren’t editable as you would expect (not supported right now), or making changes in the individual inline styles of the element take no effect (which would clearly be a bug) ?

Hi,

I was going to take some screenshots, but I was stopped by another problem, which I’ll document here and then in the next post show an example of a property not updating.

So here, I have a Label inside of a VisualElement called #title, inside #popupFrame. This is the title bar in Game view in the bottom right.

When I select this label, no parameters are printed, and I instead get the exception pasted below.

And here’s the CSS:

Exception:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.<FindStyleSheets>g__RecursivePrintStyleSheetNames|4_0 (UnityEngine.UIElements.StyleSheet importedSheet, UnityEditor.UIElements.Debugger.MatchedRulesExtractor+<>c__DisplayClass4_0& , UnityEditor.UIElements.Debugger.MatchedRulesExtractor+<>c__DisplayClass4_1& ) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.<FindStyleSheets>g__RecursivePrintStyleSheetNames|4_0 (UnityEngine.UIElements.StyleSheet importedSheet, UnityEditor.UIElements.Debugger.MatchedRulesExtractor+<>c__DisplayClass4_0& , UnityEditor.UIElements.Debugger.MatchedRulesExtractor+<>c__DisplayClass4_1& ) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindStyleSheets (UnityEngine.UIElements.VisualElement cursor, UnityEngine.UIElements.StyleMatchingContext matchingContext) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindStyleSheets (UnityEngine.UIElements.VisualElement cursor, UnityEngine.UIElements.StyleMatchingContext matchingContext) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindStyleSheets (UnityEngine.UIElements.VisualElement cursor, UnityEngine.UIElements.StyleMatchingContext matchingContext) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindStyleSheets (UnityEngine.UIElements.VisualElement cursor, UnityEngine.UIElements.StyleMatchingContext matchingContext) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindStyleSheets (UnityEngine.UIElements.VisualElement cursor, UnityEngine.UIElements.StyleMatchingContext matchingContext) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindStyleSheets (UnityEngine.UIElements.VisualElement cursor, UnityEngine.UIElements.StyleMatchingContext matchingContext) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindStyleSheets (UnityEngine.UIElements.VisualElement cursor, UnityEngine.UIElements.StyleMatchingContext matchingContext) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.MatchedRulesExtractor.FindMatchingRules (UnityEngine.UIElements.VisualElement target) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.StylesDebugger.GetElementMatchers () (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.StylesDebugger.set_selectedElement (UnityEngine.UIElements.VisualElement value) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.StylesDebugger.<.ctor>b__9_1 (UnityEngine.UIElements.VisualElement element) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.DebuggerSelection.set_element (UnityEngine.UIElements.VisualElement value) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.UIElementsDebuggerImpl.SelectElement (UnityEngine.UIElements.VisualElement ve) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEditor.UIElements.Debugger.DebuggerTreeView.<RebuildTree>b__24_1 (System.Collections.Generic.IEnumerable`1[T] items) (at <40f9e047597246a5ab2827da20f34a52>:0)
UnityEngine.UIElements.InternalTreeView.OnSelectionChange (System.Collections.Generic.IEnumerable`1[T] selectedListItems) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.NotifyOfSelectionChange () (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.SetSelectionInternal (System.Collections.Generic.IEnumerable`1[T] indices, System.Boolean sendNotification) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.SetSelection (System.Collections.Generic.IEnumerable`1[T] indices) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.SetSelection (System.Int32 index) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.DoSelect (UnityEngine.Vector2 localPosition, System.Int32 clickCount, System.Boolean actionKey, System.Boolean shiftKey) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.ProcessPointerDown (UnityEngine.UIElements.IPointerEvent evt) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVerticalCollectionView.OnPointerDown (UnityEngine.UIElements.PointerDownEvent evt) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.EventCallbackFunctor`1[TEventType].Invoke (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.EventCallbackRegistry.InvokeCallbacks (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.PropagationPhase propagationPhase) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.CallbackEventHandler.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.PointerEventDispatchingStrategy.SendEventToTarget (UnityEngine.UIElements.EventBase evt) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.PointerEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <7a35ce877df342ebba23a623ded66776>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <ae7f5af45fd74d6f8ef88ea586136af6>:0)

Ok thanks. That’s probably why the debugger is broken.

I’ve seen this issue recently too. Can you reimport all TSS and USS files in your project and see if there any broken paths?

Hi,

Actually, the debugger has broken for me. I get the above exception on practically all clicks in the debugger. The Unity version hasn’t changed (2021.2.0b7.3246), but my USS structure might have changed.

Previously, I would have separate stylesheet for special panels, and when I loaded and added such a panel to the UI root, I’d also attach a corresponding stylesheet just to this panel. But it was too hard to do constants, since globals wouldn’t be visible to the ad-hoc’ly attached stylesheets, so I bought everything together in a single .TSS file:

@import url("unity-theme://default");

/***** GENERAL STYLES *****/

@import url("USS/Default.uss");
@import url("USS/ScrollBars.uss");

/***** SPECIAL AREAS *****/

@import url("Panels/Popup Style.uss");
@import url("Panels/HUD Style.uss");
@import url("Panels/BottomBar Style.uss");

All my USS should be pretty by the book, I’m not an advanced CSS dev making high demands of USS. But since this worked 1-2 days ago on the same setup, there has to be something in the way the USS files are structured or imported that’s causing this.

No difference. Also, I get the exception no matter which item I click in the debugger tree. I’ll try to remove some USS imports and see if anything changes.

I am not arguing about that, I am simply trying to diagnose the issue with you :slight_smile: Thanks for your patience.

Actually, big difference, I have the cause of the exception.

At the top of one of the USS files dedicated to a special panel (and intended to be loaded at runtime while the panel was being instantiated), I was importing Constants.uss. I then thought it was ugly they had to import their own constants, and went back to one big USS load at boot.

But the import was left behind at the top of one of the files, even though Constants.uss doesn’t exist anymore:

Removing this, the exception is gone. So it sounds like there’s a File Not Found thing that needs a more articulated error.

There should be a warning about this broken path but I agree they can go unnoticed fairly easily. We do not have a good way to report asset-related errors in Unity I am afraid :frowning:

There’s no warning. Not when switching back from VS Code, and not when pressing Play.

And now for the actual test, it’s now working. I’m clearly able to change properties and get live feedback.

My explanation would have to be that prior to yesterday, these stylesheets weren’t part of the @imports in the .TSS file, but were instead added at runtime, using code like this:

        hud.styleSheets.Add(Resources.Load<StyleSheet>("Panels/HUD Style"));

It sounds like this might make the USS invisible to the debugger. But this is clearly working now that all USS is imported from the .TSS file.

So, I guess in principle, the debugger shouldn’t care where the USS came from. But I’ve fallen out of love with importing stylesheets at runtime, because they seem to run with other assumptions, for example without access to variables. It felt too unusual, so I went back to one big conservative import at boot.

That’s unexpected, this should clearly give a warning in the console every time the USS file containing the broken import is re-imported.

7431773--910220--warning.png

It definitely doesn’t in my case, I’ve triple-checked.

But keep in mind that this is an @ inside of an @ . You could imagine that the way it’s nested in the code makes it harder to have a return path for errors. Please see if you can reproduce this with a broken @ in a file that is itself imported.

What version of UI Toolkit are you using ?

I’m in the latest Unity beta 2021.2.0b7.3246, so I don’t see it as a separate install. Under Built-In packages, I see UIElements 1.0.0.

1 Like