Skip to content

Commit cd36186

Browse files
committed
Cleaned up RNG seeds based upon Unity docs for caching
1 parent 015bcd2 commit cd36186

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

Assets/FluidBehaviorTree/Scripts/Tasks/Conditions/RandomChance.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,23 @@
22

33
namespace Adnc.FluidBT.Tasks {
44
public class RandomChance : ConditionBase {
5-
private Random.State _state;
6-
75
public float chance = 1;
86
public float outOf = 1;
97
public int seed;
108

11-
protected override void OnInit () {
9+
protected override bool OnUpdate () {
1210
var oldState = Random.state;
1311

1412
if (seed != 0) {
1513
Random.InitState(seed);
1614
}
17-
18-
_state = Random.state;
19-
Random.state = oldState;
20-
}
21-
22-
protected override bool OnUpdate () {
23-
var oldState = Random.state;
24-
Random.state = _state;
2515

2616
var percentage = chance / outOf;
2717
var rng = Random.value;
28-
29-
Random.state = oldState;
18+
19+
if (seed != 0) {
20+
Random.state = oldState;
21+
}
3022

3123
return rng <= percentage;
3224
}

0 commit comments

Comments
 (0)