Search Unity

Question Transition when VisualElement changes size not working?

Discussion in 'UI Toolkit' started by tattyd, Oct 22, 2022.

  1. tattyd

    tattyd

    Joined:
    Feb 17, 2020
    Posts:
    14
    Hey,

    I have a VisualElement with a 1s transition on "all" properties.

    I then change the children of the element, which causes the element to change size to fit the children. I'm hoping to obtain the effect that the parent element transitions smoothly in size as the child elements change, but it seems to not transition :/

    I double checked the transition settings by tweaking opacity, which works as expected. I'm assuming this might be because height/width is always set to "auto", and it's just the computed style, not the actual width/height, that's getting changed.

    Would love any thoughts people have in this space...
     
  2. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    575
    you need to set the transition on the child too, as the width of the child and what is affect is not "transitioned" otherwise
     
  3. tattyd

    tattyd

    Joined:
    Feb 17, 2020
    Posts:
    14
    Thanks Simon!

    So my setup is:

    Parent visualelement: transition: 0.5s
    -- child visualelement (which I then change around the children of): transition: 0.5s

    Even with both of those set to 0.5s, I'm not seeing any transition :/ Any ideas?
     
  4. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    575
    is the transition property of the child set to include width?
     
  5. tattyd

    tattyd

    Joined:
    Feb 17, 2020
    Posts:
    14
    Hey!

    Sorry for the delay replying. Yes, the child container is set to all: 0.5s, as is the parent VE, there's two other children off the parent as well and they both have all: 0.5s transitions. However, when I add/remove VEs to that child container (it's a floating tutorial window with varying instructions, and I'm hoping to have the window smoothly expand/contract) it just instantly changes size.
     
  6. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    575
    You need to have not only the transition-duration but also the transition-property set in the child. I feel that is just what is missing.
     
  7. tattyd

    tattyd

    Joined:
    Feb 17, 2020
    Posts:
    14
    Thanks Simon for the help here! :) This is my .uxml:

    <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
    <ui:VisualElement class="panel" style="max-width: 600px; transition-duration: 0.5s; transition-property: height; opacity: 1;">
    <ui:VisualElement style="flex-direction: row; transition-duration: 0.5s;">
    <ui:Label text="Tutorial Sample Title" display-tooltip-when-elided="true" name="tutorial-title" class="stat-text" style="transition-duration: 0.5s; flex-grow: 1;" />
    <ui:VisualElement name="tutorial-close" class="hover-tint-orange" style="background-image: resource(&apos;textures/icons/close_FILL0_wght700_GRAD0_opsz48&apos;); width: 40px; height: 40px; flex-grow: 0; flex-shrink: 0; -unity-background-scale-mode: scale-to-fit;" />
    </ui:VisualElement>
    <ui:VisualElement name="tutorial-step-container" style="display: flex; height: auto; transition-duration: 0.5s; transition-property: height;" />
    <ui:VisualElement style="padding-top: 10px; align-items: flex-end; transition-duration: 0.5s;">
    <ui:Button text="Next" display-tooltip-when-elided="true" focusable="false" name="next-button" class="cs-button" style="align-items: flex-start; flex-direction: row;" />
    </ui:VisualElement>
    </ui:VisualElement>
    </ui:UXML>


    And here's the relevant part of C# where I manipulate the view:

    Code (CSharp):
    1.         private void ProcessNextStep()
    2.         {          
    3.             if (StepEnumerator.MoveNext())
    4.             {
    5.                 TutorialStep step = new();
    6.  
    7.                 ActiveStep = StepEnumerator.Current;
    8.                 step.SetStep(ActiveStep, StepCompleted);
    9.  
    10.                 this.Q<VisualElement>("tutorial-step-container").Clear();
    11.                 this.Q<VisualElement>("tutorial-step-container").Add(step);
    12.  
    13.             }
    14.             else
    15.             {
    16.                 // Tutorial is complete. Close the tutorial window.
    17.                 this.RemoveFromHierarchy();
    18.             }
    19.         }
    Still seeing instantaneous transitions, rather than a smooth size change :/ Any ideas?
     
  8. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    575
    Oh, as you are removing the item from the hierarchy, the structure of the project changes and I don't think we could transition the properties in that case.

    You could force the width of the tutorial to go to 0 for example, and use the transition end event to trigger the RemoveFromHierarchy.
     
  9. tattyd

    tattyd

    Joined:
    Feb 17, 2020
    Posts:
    14
    Ah, thanks for that clarification. I will think a bit about how to cleverly work around that. :) Thanks for the replies!
     
  10. tommyfan34

    tommyfan34

    Joined:
    Jun 15, 2022
    Posts:
    1
    Hi I've got the same problem here, may I ask whether you figured out this?