I have bunch of blueprint actors, let’s say it’s simple spheres which can be blue or red. Any event makes random boolean and switch material color to red if boolean==true, if ==false to blue.
Then I separated those actors into few groups. Now I want event makes theis color random, but exact the same per group.
Firstly I thought random boolean from stream will help, but it always generates identical boolean result. For seed 0 it’s always red, for 1 blue, for 2 blue and so on. Adding any random value after random stream gives random end value per actor. I want each time event hits, each actor with identical seed get the same color.
How it’s possible to make seed for blueprint actors to get same random result? Any ideas?
Thanks in advance.
Make a Dispatcher somewhere (take Game Mode as example) and call it “OnSphereColorChange” add a int (GroupID) and bool (or Color) as parameter. Inside your Sphere BP get your Game Mode (Cast to you GM) and type “Assign OnSphereColorChange” that will create a Binding everytime the Dispatcher is called you get notified. Make a Int Var and call it “MyGroupID” and Expose it so you can Edit it outside or assign a ID during Spawn. In the Bound event simply check if the ID that comes in is the same as “MyGroupID” if that is true do your Color switch otherwise ignore it.
Now all its left is to Simply Call “OnSphereColorChange” inside your Game Mode and pass it the group you want to change and the random bool/color and all of your Sphere BPs get notified.
Good Luck and have Fun.
It’s a bit unclear for me, where in this case we assign color to group? Could you please prodive some pictures?
In my case every begin play event I want each group of Sphere BPs get their own random color. On the first run all spheres on the right become lime green, spheres on the left - dark blue. On the second run - left ones become pink, right ones - black, on third - yellow and brown, etc. And there will be a lot of different groups…
My Character (can be anything you want including triggers) https://i.imgur.com/smUvRSm.png
The Sphere BP https://i.imgur.com/fPRLVUD.png
In my case I assigned the ID directly via Viewport but you can do it via Code to or during the Spawning Process. Thats really up to you https://i.imgur.com/5DUL6uO.png
And the Result 1 & 2 give a fixed color and 3 is randomly choosing a color between yellow and Purple alternating between groups. Screen capture - 77d5af894648da9bd97d41af62320dd6 - Gyazo
In the Game Mode theres just the Dispatcher and the Material just has that Named Color Parameter. Thats it =)
Oh, I got it finally. Yep, this is exactly what I needed. Kinda simple actually.
Thanks a lot!
Is this gonna work with level blueprint?
I’d prefer to have eventdispatcher inside level blueprint instead of gamemode or character. It’s changing color but ignoring grouping.
Oh come on x) don´t do that. I don´t want to encourage Bad habbits. also your logic is messed up badly.