-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weighted random selectors/sequences #194
Comments
There has been some discussion about this in #74 before. One reason we decided against a weight property is that it would only be useful for specific use cases but every single node would always have a weighted property even if it is not used 99% of the time. Another idea we had was to introduce a
|
I think having a weighted decorator would be an acceptable compromise between achieving the desired functionality, while keeping the base class relatively clean. The obvious downside, however, would be an increasingly complex behaviour tree that may be less readable than having an exported weight property. I do wonder if there's a case to be made for having some sort of "meta-properties" section available to all nodes for things like this (the blackboard comes to mind, but this would be more of a tool thing). The logic would be fully contained within the BeehaveNode class, and since it's a |
A dedicated 'meta' section would indeed be useful - it could even sit in its own export category which Godot 4 supports. One way I try to imagine weights is by thinking about graphs for a moment. Technically, any behavior tree is a directed graph mathematically speaking. Weights are usually a property of the 'edge' or 'connection' but this is not trivial to model in Godot, especially since Beehave is utilizing the node system. One compromise could be indeed to always add it to the node itself as a property with some options:
I am happy for whoever picks this up to proceed with adding weights as a new property to nodes inside a metadata category. Please also make sure to add extensive tests for this as well as update the beehave docs. Learn more about contributing to this addon here. |
I thought of an alternative: make the weights an "advanced" property of the RandomSelector/Sequence. They would be basically a dictionary of the child nodes with a number between 0.0 and 1.0. I will try to make a PR to show what I mean cause it would be easier to visualize. However, I will probably have to think of a way to make sure it works and the weights are updated when adding nodes at runtime. |
Is your feature request related to a problem? Please describe.
In some use-cases (especially procedural generation), it is desired to select a random child node based on a weighted probability. For example:
-- Child Node One (weight: 5)
-- Child Node Two (weight: 7)
-- Child Node Three (weight: 3)
Sum: 5+7+3 = 15
"Child Node One" has a (5/15) = 33% chance of selection
"Child Node Two" has a (7/15) = 47% chance of selection
"Child Node Three" has a (3/15) = 20% chance of selection
Describe the solution you'd like
A way in which to assign a weight to a node, and have the parent composite choose one of the children based on a weighted probability.
One possible solution would be to expose a
weight
variable inbeehave_node.gd
which would be1
by default (it would likely need to be part of this base class in order to apply to all nodes and properly support nested trees). When a composite evaluates its children, it will sum up the weights of all children which inherit fromBeehaveNode
which, with a weight of 1, will just return the number of children and select one of them at random with equal probability. This matches the existing behaviour of sequence_random / selector_random composites. Changing the weights would skew the random selection according to the sum of weighted values.Describe alternatives you've considered
The current functionality of Beehave allows for random selectors and sequences, but does not currently support the ability to give weights to nodes in the random selection process.
The text was updated successfully, but these errors were encountered: