bitbrain / beehave

🐝 behavior tree AI for Godot Engine
https://bitbra.in/beehave
MIT License
1.85k stars 116 forks source link

RandomizedComposite weights getting reset after switching nodes in the editor #328

Closed ksmithdev closed 4 months ago

ksmithdev commented 4 months ago

Godot version: v4.2.1.stable.mono.official [b09f793f5]

Describe the bug The weights for SelectorRandomComposite (and I assume SequencerRandomComposite) get reset to 1 after switching away and back to the node.

To Reproduce Steps to reproduce the behavior:

  1. Create a new project
  2. Install the latest beehave plugin
  3. Create a Node3D
  4. Add BeehaveTree and Blackboard nodes
  5. Add a SelectorRandomComposite to the BeehaveTree node
  6. Add three ActionLeaf nodes to the SelectorRandomComposite node
  7. Check the Use Weight property on the SelectorRandomComposite and set the weight for the 3rd node to 10
  8. Create a Game node and add the Node3D node created above
  9. Check weights for SelectorRandomComposite and see they're all back to 1
  10. Reset 3rd weight to 10
  11. Switch back to Game node
  12. Switch back to Node3D and see they're all back to 1 again

Expected behavior Setting weights in a RandomizedComposite should never reset unless changing the number of nodes.

Screenshots image image image

Desktop (please complete the following information):

Additional context The issue might be in the RandomizedComposite root node when _on_child_exiting_tree is called. The child looks like it's being removed and the weights are being reset? https://github.com/bitbrain/beehave/blob/godot-4.x/addons/beehave/nodes/composites/randomized_composite.gd#L127-L129

ksmithdev commented 4 months ago

This block of code does seem to be the culprit: https://github.com/bitbrain/beehave/blob/godot-4.x/addons/beehave/nodes/composites/randomized_composite.gd#L127-L129

When navigating away from the scene, it removes the weight information from each child as it's treated like the child was deleted. Navigating back restores the children but the weights are all reset to 1.

ksmithdev commented 4 months ago

Resolved with PR #329