Skip to main content
D
1mo ago

Unable to trigger all animated states

Hey Rive - developer here trying to work with a rive animation from an animator.

Device: iPhone
Language: Flutter

Problem:
My animation includes a single state machine called 'Superbiome_States', within that are two inputs, 'Hats' & 'States'. I am able to correctly load & trigger between these states, however some parts of the animation are missing. When 'States' is set to 4 the character is crying and there should be tears. When 'States' is set to 5 the character is jumping and there should be animated love hearts above.

Using this preview website (https://www.rive.rip/) I am able to preview the .riv file and the tears / love hearts correctly show, but when I use that same .riv file in flutter and move between the same inputs, the tears / love hearts do not show.

Code snippet:

class RiveTwoInputsExample extends StatefulWidget {
  @override
  _RiveTwoInputsExampleState createState() => _RiveTwoInputsExampleState();
}

class _RiveTwoInputsExampleState extends State<RiveTwoInputsExample> {
  Artboard? _artboard;
  SMIInput<double>? _hatsInput;
  SMIInput<double>? _statesInput;

  @override
  void initState() {
    super.initState();
    _loadRiveFile();
  }

  Future<void> _loadRiveFile() async {
    await RiveFile.initialize();
    final data = await rootBundle.load('assets/character/superbiome.riv');
    final file = RiveFile.import(data);
    final artboard = file.mainArtboard;

    final controller = StateMachineController.fromArtboard(
      artboard,
      'Superbiome_States',
    );
    if (controller != null) {
      artboard.addController(controller);

      // Find inputs
      setState(() {
        _artboard = artboard;
        _hatsInput = controller.findInput<double>('Hats');
        _statesInput = controller.findInput<double>('States');
        ;
      });
    }
  }

  void _updateHats(double value) {
    if (_hatsInput != null) {
      _hatsInput!.value = value;
    }
  }

  void _updateStates(double value) {
    if (_statesInput != null) {
      _statesInput!.value = value;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Rive Two Inputs Example"),
      ),
      body: SafeArea(
        child: Column(
          children: [
            Expanded(
              child: _artboard == null
                  ? const Center(child: CircularProgressIndicator())
                  : Rive(artboard: _artboard!),
            ),
            SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Row(
                children: List.generate(
                  7,
                  (index) => ElevatedButton(
                    onPressed: () => _updateHats(index.toDouble()),
                    child: Text(index.toString()),
                  ),
                ),
              ),
            ),
            SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Row(
                children: List.generate(
                  6,
                  (index) => ElevatedButton(
                    onPressed: () => _updateStates(index + 1),
                    child: Text('${index + 1}'),
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}


Below I have attached videos of the previews with tears / hearts & triggering the same state on iPhone simulator. I have also attached riv/rev files.

superbiome.rev
285 KB
superbiome.riv
118 KB
4 replies
D
1mo ago

Rive.rip is a 3rd party tool, not something built by Rive, but I'm pretty sure they're just using the JS runtime to preview the .riv files. Can you tell me which version of the Flutter runtime you're using? Do you know if the hats work? I ask because I'm curious if any nested artboards are working for you.

1mo ago

Ah! I was wondering about rive_rip 🤔

What ever happened to the official preview tool on the Rive site (https://rive.app/preview/)? It's gone but rive_rip links to it, making it appear as if rive_rip is an official Rive effort.

D
1mo ago

Thanks for the reply

I am using rive version 0.13.20 (latest available).

The hats do not work when using flutter, but they do when using Rive.rip, even though I am using the same State Machine / Inputs.

Would I have to do something to enable nested artboards?

D
1mo ago

An update, my designer removed the nested layers - and now it works as expected. Attached the updated riv file.

superbiome_v_2.riv
135 KB