I have a random stream to generate the dungeon in my project. I’m attempting to brute force doorways by having it loop through the amount of walls that exist and every “x” amount there is a chance one will spawn.
I’m using random streams for that sweet, sweet random predictability. Enter problem; the function is using the stream “pass by reference” on the input, a print string confirms this works. When the stream goes into the “switch on int using an in range from stream node” it gives a different result.
My walls are setup to spawn in the same spot based on the seed. So when I find an area that has a door, I just go back to it on the next regen. This confirms that I am getting a different result as I can see the doors aren’t spawning in the same location; despite a print string confirming the seed is the same.
Any reason why a passed random stream would not give me a predictable random? Any help appreciated, thanc.
Edit: I’m combing every inch of my function with breakpoints and print strings and everything is predictable from the stream, for some reason my doors will just not replace the same walls everytime.
I have deduced that this function is the one that is the current bane of my existence. Pass by reference is true. Print string gives different results everytime irregardless of seed.
Random Int in Range from Stream is still a random int. Stream ensures that the integers will be the same on same iterations, not every time.
Example: you get Random Int in Range [0-10] from Stream. You start a game and activate the random int node 5 times. You get, let’s say, 8-0-3-1-6.
Now you close the game and start it again and activate the random node 5 times again. You get 8-0-3-1-6 again. But if you continue calling this node, the result will still be random every time.
In your case, maybe at some point try resetting the stream by using [Set Random Stream Seed] node, using the same seed that was used initially. This way you’ll start getting the same values again.
Would the stream go into the stream or do I break it into an int and use that as the initial seed? There doesn’t seem to be an output either I need a variable to plug into my random int in range.
So what happens is it gets a random available “wall tile” does a radius trace around its location to make check for all “good walls”. The seed seems to give me the same results for both of these confirmed with a string.
It will then “roll” for a chance that the walls become doors, it takes the walls’s location (that pass the check) to an array and then remove the wall instances from the level.
Then at the end it will for each loop through each vector and add a door. For some reason my vector always returns similar locations.
So maybe it’s x50y30, x80y50 and x75y90. Then next time it will be almost the exact location again.
So I think it is the function that rolls for the removal chance, pass by ref is enabled.
So I just keep it plugged in like it already is but throw that reset on it somewhere? What I’m saying is shouldn’t those two functions have an output of the stream?
BTW, you can use Random Bool with Weight from Stream to have that 5% chance, instead of having this large switch.
That sounds great, got some stuff to rework now lmao.
Yeah every step of the journey is random from the stream so every level will be the same if it has the same seed.
It all seems to be just a-okay until it reaches the chance part and then no matter how I pass the stream in or reset it, it seems to just break down. No idea why though.
The sequence of calling the Stream probably changes somewhere for some reason and you get a different result. I’m afraid you’ll just have to take your time and debug it step by step.
Hmm is it possible that traces randomly sort their hits when it’s put into a hit array? Say if it traces 5 available walls and orders them x way then the next time it has them in a slightly different order?
That’s the only thing I can possibly think of, if it orders the walls differently that would explain the slight location variance on the doors.
Edit: after some testing that seems to be the exact issue, the trace comes out with say x-1, x-2, x-3, and then the next time it might be x-1, x-3, x-2… Do you know if it is possible to take the out hits and sort them?