# Random seed on EventBegin Play

**URL:** <https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309>\
**Category:** Blueprint\
**Tags:** unreal-engine, UE5-0, UE4-27, Blueprint, question\
**Created:** [February 15, 2022, 2:20pm UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309 "2022-02-15T14:20:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![synteza\_danych](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@synteza\_danych](https://forums.unrealengine.com/u/synteza_danych)\
**Post date:** [February 15, 2022, 2:20pm UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/1 "2022-02-15T14:20:15Z")

</div>

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!

 ![obraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/6/0/c607fa20adb13877f4eb296687d5e23d8f3abcea.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [February 15, 2022, 2:22pm UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/2 "2022-02-15T14:22:35Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![synteza\_danych](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@synteza\_danych](https://forums.unrealengine.com/u/synteza_danych)\
**Post date:** [February 16, 2022, 7:45am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/3 "2022-02-16T07:45:10Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![BDC\_Patrick](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bdc_patrick/32/1104221_2.png) [@BDC\_Patrick](https://forums.unrealengine.com/u/BDC_Patrick)\
**Post date:** [February 16, 2022, 7:54am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/4 "2022-02-16T07:54:09Z")

</div>

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:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/7/e/a7e3b09f02300a9304dafb84d775275588610a69.jpeg "WTF Is? A GameInstance Object") ](https://www.youtube.com/watch?v=Mg_DtpnZVlo)

and

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/1/7b11150d2dfb9ab9d4e2f4dfb2cd7cedb4e480c9.jpeg "HTF do I? Use the GameInstance Object in Unreal Engine 4") ](https://www.youtube.com/watch?v=5w594D3qtLs)

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

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [February 16, 2022, 8:13am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/5 "2022-02-16T08:13:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![synteza\_danych](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@synteza\_danych](https://forums.unrealengine.com/u/synteza_danych)\
**Post date:** [February 16, 2022, 9:20am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/6 "2022-02-16T09:20:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 16, 2022, 9:25am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/7 "2022-02-16T09:25:59Z")

</div>

> [@synteza\_danych](#):
>
> 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.

> **[Saving and Loading Your Game](https://docs.unrealengine.com/4.26/en-US/InteractiveExperiences/SaveGame/)**
>
> Overview of how to save and load your game

---

<div class="post-metadata">

**Author:** ![synteza\_danych](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@synteza\_danych](https://forums.unrealengine.com/u/synteza_danych)\
**Post date:** [February 16, 2022, 9:34am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/8 "2022-02-16T09:34:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 16, 2022, 9:35am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/9 "2022-02-16T09:35:47Z")

</div>

If you want a value to persist between _application_ launches, you must use a Save _Game_ object.

---

<div class="post-metadata">

**Author:** ![synteza\_danych](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@synteza\_danych](https://forums.unrealengine.com/u/synteza_danych)\
**Post date:** [February 16, 2022, 10:01am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/10 "2022-02-16T10:01:21Z")

</div>

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.

 ![obraz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/6/1/26160ba3fb40c599754dfda16e1df2ad3a46d343.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [February 16, 2022, 10:05am UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/11 "2022-02-16T10:05:13Z")

</div>

> [@synteza\_danych](#):
>
> beginplays

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

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/f/6/9f6cc3485424aa4147b879d694a6ecbc7b57a412.png)

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.

---

<div class="post-metadata">

**Author:** ![synteza\_danych](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@synteza\_danych](https://forums.unrealengine.com/u/synteza_danych)\
**Post date:** [February 16, 2022, 1:47pm UTC](https://forums.unrealengine.com/t/random-seed-on-eventbegin-play/498309/13 "2022-02-16T13:47:46Z")

</div>

Ok, thanks You guys for help!
