The mystery of randomization in Construction Script

Let’s get straight to the point.

An actor has been created to randomly change its mesh (first switch on int min 0 max 1), and also its material (second switch on int min 0 max 14), as seen in the following image:

… the selection of the switch on int is chosen by this logic:

Via “BeginPlay”, everytime the level is loaded, this piece of blueprint is executed and calculated. Which seems to be perfect, I want that object to be different every time the game is played. The problem is, every instance of this actor placed in the level is then the same. The idea is that all of them need to be different.

Via “ConstructionScript”, this last problem seems to be solved. Nonetheless, turns out it isn’t. Yes it does randomize all the instances of the same actor in the level, but because the random logic is being chosen from the construction script, in the packaged shipping build of the game (the .exe file that the players will use to play), they will stay the same forever.

After a lot of time spent using trial and error, searching in the documentation and using google to find a solution to this, I’ve finally reached the point where I need YOU, Unreal pro users.

Any help will be really appreciated.

Peace!

Not sure if you understand the random range from stream, which will give the same result from the same input, which is their intent.
By either replacing them with, or inserting, a couple of randomization points you would create diversity.

Yes I do. Thats why I am getting the stream from the actual time, even in miliseconds, to make sure they all get a different seed even if they are created some ms apart.

Would you be so kind to illustrate it with a couple screenshots? Thank you for your time.

Thing is, I don’t see the point in the stream. If you want them to be random, just use the random.
If you want to random something but always want the same result from the same input, use the stream.

Here I am generating random numbers 1-100 inside the construction script.


With the stream, there are always duplicates. Not that I get why, I’m not the pro user you’re looking for. By introducing a random int for the stream, that results in a random stream… but then that’s the same as not using the stream.

Hey there!

Just tested out what you said and the results I get are still not what I am looking for.

The point is: I need to get different results on the build. So, whenever I open / close the (packaged build ready for shipping) game, it will be random each time. Which wont happen with any of the methods that have been proposed so far.

By the way, that’s the reason why I chose to use Random Int in Range From Stream with the stream input being the current time, to ensure that it would give a different seed every time the game was executed.

Oh, so an instance placed in the world is never going to have its construction script execute in a build? I did not know that.

Then the only thing I can think of is to move the randomization to begin play.

Well, as I stated in my first post:

It just happens to give every instance the exact same random output.

A possible workaround came recently to my mind: giving the BP Actor a public int variable which would work as an “ID”, so the “BeginPlay” could use that number to switch on int (maybe?) and give a different output to each instance of the BP Actor in the level.
Still, I’m not very sure about that.

Have you tried the “Random Int in Range” node?

Both Random Int in Range and Random Int in Range from Stream, as stated above.

@anonymous_user_e9cedc6b:

I think your problem lies in the generation itself (timewise). When Event begin play is called, it calls every actor of the same type at the exact same time. This also depends on the strength of each individual computer, how fast it can process objects per frame or per millisecond. I recreated your setup and sometimes I get exactly the same material and sometimes I do not. Stream is also based on a numeric algorithm, which is predictable and can cause these kind of effects, if it is run in the same timeframe or in a similar timeframe.
Are your objects visible for the player on start? If not, just plug a “delay” node after the “event begin play” node. In the “duration” pin, plug a “random float in range” node and type in as min value = 0.01 and as max value = 1.

That way we can give the algorithm a little bit more time to generate different enough numbers and randomize them to your liking. And in a packaged build the computer responds way faster not running the Unreal editor in the background. This will amplify your problem you are dealing with. So if your objects aren’t appearently visible for the player for around 1 second, the delay might work for you.

But that’s because you’re using the random stream node, right? The random without stream, on begin play should randomize… evenly.

Also, what is suggested above is like saying
“my stream always gives the same value. Let’s randomize the stream, so I get a random number.” But then that’s the same as not using the stream.
Since there is no indication that an actual use for a stream (like, having a seed entered when starting the map, like minecraft) having a stream seems redundant to me. But maybe I am missing something.

I’ve though of this but never really tried to do it because at first it didn’t make any sense from my perspective.

Tested it and yes, it works. I’m going to use this solution as a workaround until I get to find another solution that doesn’t rely on a timespan to get the same results.

Thank you for your time and unique ideas!