Random seed on EventBegin Play

Hey, i have a scene with a lot of randomly spawned meshes and materials. I would like to control the random seed with one master seed controller in between blueprints if it’s possible or have a setup for incremental versioning, for example- default seed value is 0, then every event begin play it adds +1 to the seed. How can i do this math? Here is my current setup for spawning random object with random position and rotation in range. Greets!

You can keep the seed in the game instance or the save game.

If this in level BP code, then game instance would make more sense I guess. Because you can load the level from there.

Meh, or save game with level BP would work…

Thanks for the answer! I’m afraid i didn’t understand anything though lol. I’m a beginner, could You explain it in more detail please? Greets. :slight_smile:

right click in the content browser > Blueprint > Blueprint Class

search there for “GameInstance”

Create it and rename it.

Go to the Project Preferences > Maps and Modes > set your newly created Game Instance there.

now you open your GameInstance. it works like every Blueprint is working… So you can create Variables here.

The Difference to a normal Blueprint is the Fact, that a GameInstance is persistent during the whole Game. It is loaded on Game Startup, and Destroyed on Game Quitting. Inbetween, everything stays alive.
So, if you save a Seed here, it will stay there until you close the Game.

To get/set variables of your GameInstance from a Blueprint, go that way:

In your Blueprint (Character, Environment, NPC… etc) right click in the Graph and search for the Node “Get GameInstance” and place it.

from this Node, drag a Wire and type in “Cast to XXXX”, where XXXX should be the Name of your newly created GameInstance.

from the Cast node, you can get/set Variables of the GameInstance and call functions and events inside the Instance.

For more Infos, try to search for some Tutorials on YouTube.

Two Examples:


PS.: Try to search for Tutorials about SaveGameObjects, too.

Tell me if you can’t figure it from what’s below, and I’ll chime in…

Thanks! [BDC_Patrick] and [ClockworkOcean] I’m amazed by the speed of Your answers! Really appreciate it.

I looked into the GameInstance BP situation and it looks like it’s exactly what i need in terms of the master seed controler inbetween other blueprints.

Now i just don’t know how to set it up the way that the stream controlling the random range nodes is having an incremental n+1 value on seed every beginplay.

If by that you mean a game launch:

  • create a Save Game object and save an int variable there when the user quits
  • when we boot again:
    – check if a save game exist, if so → load the save game
    – read the value of the saved variable, add 1
    – set the New Seed for the stream.

im not making an actual game, it’s more like a rig for rendering multiple variations of a single scene. At the begining i had the normal Random Integer in Range Node and while duplicating the sequence in render queue it works really good but i wanted to introduce some control over the randomization with the stream seed.

If you want a value to persist between application launches, you must use a Save Game object.

1 Like

It can start from 0 every time the app launches. The thing i need is sth like a counter of event beginplays. So at the first play the new seed value is 0, then 1, then 2 etc.

Begin Play of what? Any blueprint and its mother will call a Begin Play. If you want to add 1, it’s:


If it needs to persist throughout a single session and you’re loading levels, keep this var in the Game Instance. If you’re not loading levels, you might as well keep it in the Game Mode or any other blueprint that is not the blueprint with the Begin Play that triggers the shown script.

I guess this blueprint gets destroyed and respawned? Is this why you refer to it as beginplays?

It really is not clear what needs to happen.

Ok, thanks You guys for help!