refreshing a random number


i’m working on a small game for the sake of learning and practicing… i’m going for an endlessly generated Terran with randomly generated obstacles (boxes)
what i did is create a bunch of planes next to each other representing the terran and they teleport (set world location) when the player is far enough…
i attached a few boxes to each plain (3) and made it so that “begin play” generate a random integer the decides the position of each box relative to the plain
i also connected it to when the plain teleports. it works perfectly when the game starts, the problem is the boxes retain there initial position no matter how many times the plain teleports. so the terran just keeps repeating itself. the problem seems to be that when the random integer is called again it doesn’t seem to refresh it’s value… so i was hoping you could help me resolve that!

sorry for the lengthy text, and thank you in advance!

Hey there,

for complex systems like this it would be helpful to see your actual project in screenshots.
Please upload screenshots showing the critical code!

If all you are doing is moving the already spawned element to a new location then yes it won’t run again because there is nothing telling it to.

What you want to do is destroy the actor and respawn it. Either that or run another random generator to move the boxes once they have teleported

thank you for the reply,
i get what you mean, but wouldn’t that cause heavy memory usage ? because it would be destroying and spawning actors rapidly, (the player moves quite fast).
if there is a way to reduce memory usage, i would use this method, it would be no problem.

I can’t imagine you are spawning thousands of actors so it should have no issues with a few dozen of them.

Just make the stuff you want to be called on BeginPlay AND Teleporting a function.
And call it on BeginPlay AND Teleporting.

No need to destroy and spawn the Actor new every time. In fact that should be avoided.
For other situations people invented pooling to not have to destroy and spawn stuff.

So just work with functions and you should be fine.

i tried that, same problem… i will be posting an image of the blueprint today…

Yeah, that would help i guess (:


the two “random integer” give the same value each time the plain is teleported, thus the boxes retain there position, weirdly the “set relative location” of the three boxes are connected after each other and they are all connected to these 2 “random integer” and they randomize the position of each box on the plain, and they also randomize the position of the boxes on other plains from each other, the problem is they don’t give a new value when the plain is teleported…