Download

Get random actor of class except for self

Hello everyone, I have a blueprint ‘Mystery Box’, this blueprint has the variable ‘Show Mystery Box’, which toggles whether or not the actor is visible. I have several of these actors placed around the level, only 1 of them can be visible at a time. I am working on an event to try and randomize which box is currently visible using this event:
Untitled-2.png

When I press x (X is set to not consume input, so this runs on every actor), the current active mystery box actor (the box that has ‘Show Mystery Box’ set to true), will pick a random index of a new mystery box actor to activate. This all works fine, but it will often pick its own index, despite me having a branch that checks for that. I am comparing the index of ‘This’ to the new picked index, if they are the same, it tries for a new random until they are different. Printing the 2 ints to screen on the False of the branch will even print 2 identical ints, though this is not possible. I also tried using a temporary int variable that stored the random int, and accessed that variable rather than the random, same problem. I also tried comparing the ‘Get’ value with self, same problem. What is going on here? What is the best method to achieve what I am doing? I have also gone as far as having an array of which actors are eligible to be picked, still does not work.

Edit: The RepNotify on the ‘Show Mystery Box’ variable just sets the visibility of the actor, I know that this part works properly.

Why not just have one of those blueprints in your level, and make your own spawn point class. Place those around your level and keep them in an array in your level blueprint.

Destroy the mystery box when you want to move it, and pass what spawn point you were currently at last time to the level blueprint and have your level bp spawn another mystery box at a spawn point that wasn’t the last one. This way, you won’t have to worry about the visibility of so many actors. :slight_smile:

With this custom spawn point you could have a static mesh there to represent that it could spawn there. It would make for a good experience for the player.

Sorry for double post, can’t edit a post without deleting it on my mobile.

In all honesty, I am not hiding the whole actor, I have a seperate mesh for when the actor is active than when it is inactive. This is for my tutorial series so I’d like it to be simple, like I had up in the screenshot, I just need a solution, not a work-around.

My bad, I was a bit confused on why you would have to many hidden meshes around. :stuck_out_tongue:

This is what I do for mine. Instead of a branch trying to redo the random int, I use a while loop.

Basically

It will keep trying random integers until it gets one that is not equal automatically. You won’t have to worry wiring an execute wire backwards too :smiley:
I am setting the Gunman variable with a randomInt just before the while loop.
newRand.png

This is like the only time I have ever needed a while loop in UE4. lol

Fixed it, looks like my computer was too fast for it’s own good. Adding a delay of .01 seconds before the ‘Toggle Show Mystery Box’ solved the problem.