Random Stream in Character; Seed has no effect?

Hello, I’m on 4.21.2.

On the level blueprint I add a Random Stream variable, then on BeginPlay, PrintString a random integer from that stream. When I change the Initial Seed in my stream variable parameters, then the random integer is different on startup. That’s the behavior I expect.

Now, if I do the exact same thing, but in the Character (for instance, in a blank 3rd person template, in ThirdPersonCharacter), then the Initial Seed has no effect. No matter the value I set it to, I will get the exact same integer from my PrintString.

Is there a reason it behaves differently in a Character, or might this be a bug?

EDIT

If prior to using my Random Stream variable I set it using a Make Random Stream node, then changing the Initial Seed in the Make Random Stream node does produce the same behavior as in the Level BP.

So my question really is - why can’t I use Initial Seed default value of the variable when in a Character BP?

Seed is a sequence distrubution that given value of initial stream. Random stream would call same sequence of distrubutions if you do not change initial seed. Therefore, invoking SetRandomStreamSeed to assign new value into your Initial Seed as property in your struct.

266615-chrome-2019-01-27-03-33-10.png

[SetRandomStreamSeed on Blueprint API][2]

Yes, I know what streams are. But why doesn’t it behave correctly when you change the initial seed in variable parameters, in a character BP? Why only when you set it through a node?

Because setting of a variable initial seed is not generating a sequence. You need to override that distribution again.

But then, why does setting of a variable initial seed work in the Level BP, and any other Actor BP, but not in Character BP? That’s what I’d like to understand. Why does it behave differently in that specific class?

Character is just derived instance of Pawn class. Therefore Pawn is a AActor so I can’t see any expectation of not working changing seed effect in character blueprint class. Check your implementation. Please check your communication between character or make sure that you call correct Stream struct you change on. Seed is independent of character blueprint classes. After that that is what recommended on documentation page of Random Streams;

To set the Initial Seed property directly on the variable, the RandomStream(instance of your struct) variable must be exposed for editing.

Random Streams on Unreal Offical Doucmentation

Thank you for trying to help, but why don’t you try it for yourself, see if you get the same result? Takes less than 5 minutes.

Start a new project, using 3rd Person template, no starter content. Open ThirdPersonCharacter BP, and do the following.

You’ll notice that whatever you set Initial Seed to before PIE, you get the exact same result.

Do the exact same setup in Level BP or Actor BP, and you’ll get a different result if you change the Initial Seed. (As I would expect it to be.)

It is expected behavior I think you misunderstood what is sequentical access happens on streams. Stream is distributed numbers of given sequence that can be calculated for can be accessed in given sequence.

I printed out that number again and accessed second generated nubmer from stream.

You might call Random Integer In Range if want to get random number between min and max numbers:

267153-ue4editor-2019-01-31-16-46-12.png

[Sequentical Access][3]

I have not missunderstood sequential access.

For example, for a random integer in range 0-10 from stream :

  • If Seed 0 generates 3, 6, 1, 5, …
  • And Seed 1 generates 4, 7, 8, 9, …

With the following BP

  • in the Level BP for Seed 0 I get 3 and 6, for Seed 1 I get 4 and 7.
  • in the Character BP for Seed 0 I get 3 and 6, for Seed 1 I STILL get 3 and 6

In the Character BP I always get 3 and 6, whatever the seed is. I want to know if there is a reason for that, and if so why. And if there is no reason it might be a bug.

Your solution is invoking the default value of initial seed is not overrided. Also Level Blueprint is different blueprint that assigns automatically assings initial seed value for stream generated objects. That’s all you need to setup like in image.

Initial value will be overrided for each generated distribution on Begin Play event.