Flutter API not registering events/input changes triggered by nested artboard event
hi there. I am on latest rive and OSX 13.3.1. testing on latest chrome.
I am trying to get events to bubble up from nested artboards. works fine in rive but when using flutter api the onEvent and onInputChanged event handlers do not fire for this nested event. If I monitor the value of the bool in the API I see it never changes either. this is despite everything triggering fine inside the rive instance and editor.
I have a nested artboard called result. when its change event is fired I want it to fire a 'result-change' event in the parent artboard or toggle the resultChanged input but nothing is working. the result-change event fires in the editor but not when I try to listen w API.
Hi
What you can do is "bubble up" events and "send down" inputs.
Here is an example of affecting nested input values using an input from the main artboard. In this example, changing the "State" input (0, 1, 2) on the main artboard transitions to a different timeline, which triggers a change in the nested input "StarState" value. It is a workaround, however, in a sense, its a bit of a nice way to encapsulate nested inputs (for example, the main artboard can expose an input that sets several nested input values, so the runtime doesn't have to worry about each of the nested inputs separately).
That example is for inputs, but in a similar way the parent artboard can listen for events from a nested artboard and report a new event.
thanks
I can see if I can find some time to recreate a stripped back example project with the problem
hey
I am really hanging in there for that data-binding feature! I know this is unsupported but if any advice on a tweak to this that could work until the feature arrives would be great. Currently I have a workaround for my project mirroring the events in the parent artboard and manually matching timing which is not ideal but seems less tedious than a bunch of boilerplate like the following which negates the benefit of having a nested artboard:
parent numeric input > 2 timelines in a blend with nested input keyframes (+ another state tab to reset input) > child input > 2 timelines in a blend for my desired animation (+ another state tab to reset input)
my code based on the answers in the flutter runtime github issues is here for reference:
import 'package:rive/rive.dart'; // ignore: implementation_imports import 'package:rive/src/runtime_nested_artboard.dart'; // ignore: implementation_imports import 'package:rive/src/rive_core/animation/nested_state_machine.dart'; mixin GameMixin { StateMachineController? getNestedController(Artboard artboard, String nestedName) { for (var nestedArtboard in artboard.activeNestedArtboards) { for (var animation in (nestedArtboard as RuntimeNestedArtboard).animations) { void callback(String stateMachineName, String stateName) => onNestedStateChange(animation.nestedArtboard?.name ?? '', stateMachineName, stateName); if (animation is NestedStateMachine) { if (animation.stateMachineInstance is RuntimeNestedStateMachineInstance) { final cache = (animation.stateMachineInstance as RuntimeNestedStateMachineInstance); final StateMachineController controller = StateMachineController( cache.stateMachineController.stateMachine, onStateChange: callback); animation.stateMachineInstance = RuntimeNestedStateMachineInstance( cache.stateMachineController.artboard as RuntimeArtboard, controller, ); String name = animation.nestedArtboard!.name; print('found nested $name'); if (nestedName == name) return controller; } } } } return null; }
I appreciate this is annoying when you and team are actively working on a completely different and superior approach to solve this type of problem!
Hi
sorry for the slow reply and thanks for humouring me
https://drive.google.com/drive/folders/13fXwvX6_X01ctaw7PP3QI8CniFOAT0o2
the problem is here where I call the above getNestedController function:
void _onRiveInit(Artboard ab) { artboard = ab; final controller = StateMachineController.fromArtboard(artboard, 'State Machine 1', onStateChange: _onStateChange); artboard.addController(controller!); controller.addEventListener(_onRiveEvent); /// if I uncomment this nested input works /// but I stop receiving the forwarded 'result-change' event: // var nestedController = getNestedController(artboard, 'score'); // var nestedInput = nestedController!.findInput<bool>('isVisible') as SMIBool; // nestedInput.value = true;
rev and riv file are in assets. with the above code uncommented some score UI appears top left
seems I can have EITHER access to nested inputs via the above hack OR I can get events forwarded from a different nested artboard to the parent artboard callback but not both :/ (a parent and a forwarded event should fire when the center popup appears in the loop)
FYI, I would also love a way to set text for text-runs with API in nested artboards (currently creating text runs in parent to overlay nested artboards and syncing animation)
Not blocking me as I have a workaround for my project and appreciate you have other priorities but if you get a chance to take a look before the data-binding feature makes this all redundant please do!
hi
the following fires in rive but not in the API:
nested artboard event > parent artboard event listens to nested event > fires parent artboard event in rive fine > but API event callback does not receive this parent event
however this workaround does work:
nested artboard event > parent artboard event listens to nested event > fires parent artboard trigger in rive > trigger changes animation timeline change with parent event reported in transition > API event callback does receive this parent event fine
I am installing this project next week so likely can't work up another example project until after then but wanted to let you know as the previous example might point you in the wrong direction. cheers.
Hi
That’s amazing
in that case I’ll hold off refactoring to remove nested artboard inputs. Hopefully the new feature will take care of this bug. Will suss it out then :)
Fingers crossed for nested events and text runs!
Nested events and text runs not yet! This is only nested inputs for now
Nested inputs are now exposed on the latest version of the runtime! See our docs: https://rive.app/community/doc/state-machines/docxeznG7iiK#nested-inputs
Amazing thanks Gordon, can’t wait to try it out over the next week :)