Please Help, How to Randomize outcomes of Triggerboxes?

Hey everyone! I’m working on setting up multiple Triggerboxes in my level, and I’d love to get some help with randomizing the outcomes for each one. For example, I have four Triggerboxes placed, and four different outcomes: a sound cue, lighting changes, and two different animations.

What I’m hoping to do is randomize which outcome happens for each Triggerbox every time a player starts the game, so they get a fresh experience on each playthrough. I’m also considering the possibility of adding additional outcomes in the future, so I’d like a system that can handle more options down the line and the trigger box can choose from the outcome library.

I’m still figuring out the best approach, so any advice or tips would be awesome! If anyone has suggestions or knows how to achieve this, I’d really appreciate the help! Thanks in advance!

1 Like

I see two ways of doing it:

If you want all four to have different functions, then you can (at the start of the game for example), randomize an array of [1, 2, 3, 4], so Box1 will have Outcome[0], Box2 will have Outcome[1], etc…

If you dont need all outcomes to be present and unique, just randomize the outcome on box creation (random number between 0 and NUM_OUTCOMES - 1)

Thanks for the reply! I think I understand what you’re saying, but just to clarify—what I’m aiming for is to have Box1 and Box2 each randomly pick from the same set of outcomes, regardless of their positions. So, for example, Box1 could have Outcome1 in one session and Outcome3 in the next, while Box2 could have a completely different random outcome each time as well.

In essence, both boxes would have access to the same 5 outcomes (Outcome1, Outcome2, Outcome3, Outcome4, Outcome5), but in each game session, they would randomly pick something from that pool. The outcomes wouldn’t be tied to their locations (like hallway or room)—just random across all boxes.

Would this still be possible to set up? I’d appreciate any further insight you can offer!

Okay, what I would do is (examples are pseudocode, not C++):

First, assume 5 boxes, and 5 different outcomes.

At the start of the game session, randomize the outcomes array:

[0, 1, 2, 3, 4] => [1, 4, 3, 0, 2] (random)

Then, also at the start of the game session (after randomizing the array), assign each box its outcome:

Box0.Outcome = Outcomes[0];
Box1.Outcome = Outcomes[1];
Box2.Outcome = Outcomes[2];
Box3.Outcome = Outcomes[3];
Box4.Outcome = Outcomes[4];

This way, every game session, each box has a unique randomized outcome.
Usually, the start of the game session if represented by the Event BeginPlay, but it could also be a custom event.

Alternatively, we could make each box choose a random outcome, without ensuring every outcome is unique and present, to do so:

Outcomes = [0, 1, 2, 3, 4]; # Not randomized

# In this case, Outcomes.Num() returns the length of the array (5)
# Assume that Random(start, end) choses a random int between start and end (included)

Box0.Outcome = Outcomes[Random(0, Outcomes.Num() - 1)];
Box1.Outcome = Outcomes[Random(0, Outcomes.Num() - 1)];
Box2.Outcome = Outcomes[Random(0, Outcomes.Num() - 1)];
Box3.Outcome = Outcomes[Random(0, Outcomes.Num() - 1)];
Box4.Outcome = Outcomes[Random(0, Outcomes.Num() - 1)];

This would make every box roll a random independant outcome, so it could be all unique or even all the same.