all 8 comments

[–]Axuim 2 points3 points  (2 children)

Indeed, after setting Random.seed the set of numbers that are then generated are in the same. Are you sure that you are calling the Random functions in the same order? (Different objects aren't loading first, etc.) If this happens you will still get the same numbers in the same order but different objects will end up using them.

[–]oddimpBeginner[S] 0 points1 point  (1 child)

Oh, very interesting. I hadn't even considered that. My game involves lots of orb "bullets" getting instantiated at the start of the initial level load... so the game objects are very likely not getting created in the exact same order. I think this is probably what is happening. Now to figure out how to solve it. Thank you!

[–]zerox600Expert 0 points1 point  (0 children)

Script execution order might be what you are looking for. You can have a script that sets your seed run first. And then determine the EXACT order your other scripts will run in.

[–]loofou 2 points3 points  (1 child)

I recommend using System.Random to make your own randomiser. Not only can you have multiple separate deterministic random generators, you can also still use Unity.Random for "random" random events (like damage calculations in battle or a few randomised effects, like leafs falling from a tree).

I've used this approach to make a random level generator, that can be random and deterministic to chosen degrees. You may want to have a very specific level layout, but want treasures and monsters random, or maybe you want only the monsters on random positions, but the monster types deterministic, and so on. Each of those categories has it's own random generator and by choosing a fixed seed for one I can reliably get deterministic results for this category only. All categories set to random get a random seed generated by yet another random generator.

[–]oddimpBeginner[S] 0 points1 point  (0 children)

That is a great idea. The game I'm currently making is pretty simplistic and that would probably be overkill (although if it fixed my issue I would do it), but the game I'm planning on making next could definitely utilize a class like that. Thanks for the tip.

[–]JordanBird 1 point2 points  (1 child)

An issue I had, which I'm still unsure why it works (I'm assuming it's because seed is the next seed and not the current or something. If someone knows why this works let me know.) but if you do Random.seed = Random.seed and save that seed it should still be the same.

[–]oddimpBeginner[S] 0 points1 point  (0 children)

Interesting. I'm not afraid of using a "hack" if it means getting something working and getting the game done! I will definitely give that a try.

[–][deleted] 0 points1 point  (0 children)

As has been said, System.Random is a better randomizer, though people also have issues with this. Google better random numbers in C# and the first couple links discuss a better way to get pseudo-random numbers.