<aside> 💡
This page assumes you know the different Godot RNG-related concepts as written in the Godot documentation. In particular, seeds and states, the seed() and randomize() functions and the RandomNumberGenerator class.
</aside>
<aside> ⚠️
From the 4.7.1, BuH uses a RandomNumberGenerator stored in the variable Spawning.RAND that has Spawning.RAND_SEED as seed. In pre-4.7.1, BuH uses the global RandomNumberGenerator.
Also note that the way the global RNG is handled has changed from Godot 3 to Godot 4 : Since Godot 4.0, the random seed is automatically set to a random value when the project starts. This means you don't need to call randomize()
in _ready()
anymore to ensure that results are random across project runs. This method should be called only once when your project starts to initialize the random seed. Calling it multiple times is unnecessary and may impact performance negatively.
For this reason, BuH 4.7.1 uses its own RNG and randomize()
calls in nodes have been removed.
If you just want to add some randomness to the properties, you don’t have to understand how it all works but if you want to control the RNG, you should understand this post : https://stackoverflow.com/questions/79434187/does-random-seeding-change-the-project-globally-or-at-the-scene-tree-level
</aside>
The plugin allows you to set the seed of the plugin’s RNG (see RAND_SEED and Randomisation. This seed will only impact the plugin and not the rest of the game. Everything random in the plugin will inherit this RNG.
If no seed is set (RAND_SEED = -1), a random one will be generated with RAND.randomize().
You can also use a RNG you created. For example, if you want your entire game to use the same RNG. Use rng_setup
and pass your RNG as an argument. Unfortunately, from what I know, Godot doesn’t allow you to get a reference to its global RNG.
<aside> 💡 Warning : using randomisation in resources will impact memory usage as explained in Randomisation : why it’s a mess
</aside>
Some of the nodes / resources have a “random” category with properties which allows you to randomize all the properties mentioned above. This is how to use them :
Leaving default values disable the randomisation.
It starts with a Randomisation Chance
property. If some of the properties below are activated, Randomisation Chance is the chance, between 0 and 1, that the randomisation will be active. If not, all the properties below are fully disabled and no randomisation will happen.
Every property of a node / resource that can be randomized follows the same naming pattern.
*Name* + Choice
: the type of this random property can be an array or a string with “;
” as delimiter. They act like lists you can add values to. When the property is used, it will randomly take one of the values in that list. If it’s an array, it expects the same value types as the original property.*Name* + Variation
: randomly tweaks the original property following a classic normal distribution with the original property value as the mean, x as the variance and y & z as the lower and upper bounds (in case you want to limit the values between 2 bounds. Else, y and z can be left as default).*Name* + Chances
: chance that the property will be enabled / disabled from 0 to 1.