skip to Main Content

I hoping somone can help with the following error I am getting

[VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Cannot find reference BonfireGameInterface in the component tree
#0      BonfireHasGameRef.gameRef (package:bonfire/util/bonfire_game_ref.dart:21:7)


Instance of 'TurnManager' cannot be added to Instance of 'BonfireGame' because it already has a
parent: Instance of 'BonfireGame'

Im currently using flutter flame engine and Bonfire. The bonfire game is embedded within the flame game. Essentially when sprite component touches an enemy component I use gameRef.overlays.add() to display the bonfire game. when the game is done i use gameRef.overlays.remove() to remove the bonfire game. The issue is the next time the play component touches an enemy component I get the above error. Any help will be greatly appreciated.

2

Answers


  1. It seems when your bonfire game is displayed via overlay, some code gets executed that tries to add a TurnManager to the bonfire game. On first display, this works fine, but on subsequent display, as that TurnManager is already child of bonfire game, attempts to re-add it causes problem.

    When the bonfire game is removed from the overlap, it goes into detached state, but all its children are still attached to it. To fix this problem, you’ll have to just check if the TurnManager in question is already added or not. If it is already added, just skip the add call.

    Login or Signup to reply.
  2. you need two steps for the solution

    1. {component}.removeFromParent();

    in this sentence, the child is removed in the component tree when disapear on the screen.

    Otherwise, the previous child will always be tied to a parent, which does not allow him to be added to a new parent

    2.You can only add the Mannager class once add({TurnManager})
    but in the TurnManager, It is possible to generate multiples gameRef.add({componentes} taking into account component.removeFromParent(); always

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search