mshvern23
Topic Author
Posts: 35
Joined: 22 May 2023, 02:00

VisualState potentially off-by-one (or just wrong) on launch

21 Aug 2023, 17:15

I have this situation specifically with my child of the main view. There's a 50% chance on launch that we I `GoToStateAction` to `first_state` I actually go to that state or go to the state after it (say `second_state`). This is fixed by restarting Unreal without changing aynthing for me, I haven't tried what happens in the shipping build yet.

The code would look something like
 <Grid x:Name="RootGrid">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ui_mode_group">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0:0:0.1"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="normal"/>
                <VisualState x:Name="none"/>
                <VisualState x:Name="minigame">
                    <Storyboard>
                       ...
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
            <VisualStateGroup x:Name="combat_state_group">
                <VisualStateGroup.Transitions>
                    <VisualTransition GeneratedDuration="0"/>
                </VisualStateGroup.Transitions>
                <VisualState x:Name="combat_inactive">
                    <Storyboard>
                       ...
                    </Storyboard>
                </VisualState>
                <VisualState x:Name="combat_active">
                    <Storyboard>
                        ...
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <b:Interaction.Triggers>
            <b:PropertyChangedTrigger Binding="{Binding widgets[global_widget].strings[mode]}">
                <b:GoToStateAction StateName="{Binding widgets[global_widget].strings[mode]}" />
            </b:PropertyChangedTrigger>
                        <b:PropertyChangedTrigger Binding="{Binding widgets[global_widget].strings[combat_state]}">
                <b:GoToStateAction StateName="{Binding widgets[global_widget].strings[combat_state]}" />
            </b:PropertyChangedTrigger>
        </b:Interaction.Triggers>
The widgets[global_widget] is an implementation detail of how I'm communicating wtih NoesisGUI, but I wanted to include that in case binding to dict inside of a dict would have some relevance. BTW, this exact model works for virtually everything else, it's only the child of the main view that has this problem.
 
User avatar
sfernandez
Site Admin
Posts: 3109
Joined: 22 Dec 2011, 19:20

Re: VisualState potentially off-by-one (or just wrong) on launch

23 Aug 2023, 17:51

You mean that GoToStateAction is invoked with the wrong StateName?
Is it possible that in those cases the name of the state is the previous value of the bound property?

Because I'm thinking that maybe the PropertyChangedTrigger is executed before the binding in the GoToStateAction is reevaluated. If that is the case the solution would be to ensure the value of the StateName property is updated when the action is invoked:
void GoToStateAction::Invoke(BaseComponent*)
{
    if (GetAssociatedObject() != 0 && mStateTarget != 0)
    {
        DataBindingHelper::EnsureBindingValue(this, StateNameProperty);
        const char* stateName = GetStateName();
        ...
    }
}

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 8 guests