Blueprint communication for a slot machine concept

So, I was having this idea of creating a simple 3 reel slot machine. I have built something similar about 15 years in Flash with AS3. About 2 months ago I rebuilt the whole thing in JS, and the idea came to me that I could probably give it a go and see if I can build this in UE.
Here’s what I have in mind and please feel free to chip in and steer me in the right direction.
I know there’s a fully working slot machine in the marketplace, but I would rather build it from scratch and learn along the way.
Not sure if this should be a full 3d project or 2.5 or just 2D since the machine itself would not be moving at all and the only thing displayed on the screen should be the visible area with the 3 reels, a couple of buttons and maybe a small area on top for displaying information.
Any suggestions are greatly appreciated and while I do have a bit of archviz xp with UE, I never dug deep into BPs and gaming functionality.
Here’s what I’m thinking and please feel free to add or suggest different approaches:

  1. the machine itself will be 3d modeled by me and I can make changes as needed.
  2. The 3 reels will basically be 3 cylinders that can rotate. Each reel has a png with a strip of images wrapped around it.
  3. The spin button, would be a box mesh that is a blueprint. On Clicked it should communicate with the BP for the reels and call a function that would randomly spin each wheel a specific n°, where n is a random number divisible to the number of symbols on each reel (making sure that the final position of the reels when they stop would be a perfectly aligned symbol).
  4. When the wheels stop spinning there should be a paytable bp that checks if the symbol combination is a win or not.

This is the basic stuff for now, and additional features could be added in the future.
Please point me in the right direction.
Thank you for taking the time to read all this and looking forward to the challenge.

To do the math is literally a couple of nodes. The challenging part is to animate the reels.

I’d create it in ‘full 3d’ - It’s possible to have a static camera. (Even an orthographic camera could be interesting)

I spent 10mins noodling with the idea and this is what I came up with:

(For a BP to receive keyboard input it needs to have a setting changed (Red Circles))

This example will rotate in both directions, but the main idea is to show an implementation of ‘Rinterp to’ node.

My idea as far as blueprint communication goes - Instead of the ‘R key’ you’d have a “Spin the wheel” function (“Custom Event node”) to control the spin and generate the result, then to pass the ‘wheel result’ to your paytable calculator: you’d create a function/custom event in your paytable with an input (and maybe an additonal input telling the paytable which of the 3 cylinder is sending the info).

Tangentially: I wonder about what sort of things a slot machine inside of a 3d engine could do that would be impossible otherwise. (Not sure if that’s a direction you’d want to take it, but ‘Pushing the medium of slot machines into its next evolution’ is where my minds at. :slot_machine: :grin:)

Great ideas. Thanks guys! If I do build it full 3D with a static camera, wouldn’t the cursor be grabbed by the engine on game play? Apologies for asking such noobish questions :slight_smile:
And I agree with you @Astrotronic it does sound a bit overkill thinking about the basic functionality of a slot machine, but I just wanted to see if it is physically possible to build such a thing. I’ll take all your input, digest it for the next couple of days and I’m sure I’ll be back with more questions :smiley:
Oh, and for the communication I do not need a keyboard input. Just mouse click on the 3d button, or touch on mobile.

Just an idea… since the reels and the spin button are all meshes modeled by me, is there even a point in separating them into 2 BPs? Or could I just create a single BP and reference and call each other from within? Just trying to simplify things if at all possible…

One BP would be fine for that kind of thing :slight_smile:

That’s controlled with the Player Controller.

If you create+assign your own PlayerController class you can set the variables directly inside of it instead of flipping them on at runtime with BP. (Same result)

Ok, here’s what I have so far:

General setup

Reels BP

Reels BP Event Graph

Camera BP

  1. When I start playing… the Event Graph from the Reels bp does nothing. No click on the button, nothing seems to work. No print no rotation.
    I initially set up the RandomNumber to 90.0 just to see if it spins at all. No movement. No Print on the screen.
  2. The camera BP does not keep the camera in place. You can still move and rotate the camera.
    Any tips are greatly appreciated

Starting with “2.” - It sounds like you’re still auto-possessing the default pawn. You need to explicitly possess the ‘CameraActorBP’ - BUT - it looks like CameraActor BP is A child of ‘CameraActor’… It needs to be a child of ‘Pawn’. (To say it a different way, a Pawn with just a camera inside of it will give you what you want) > Once it’s placed in your level select it and change ‘Auto Possess Player’ to “Player 0”

Then, for the button click, Implement the logic from my previous post and you should be able to control mouse + fire that ‘on clicked’ event

Ok, here’s the progress so far…

I added the following BPs:
BP_Pawn_Reels (type: Pawn) - where I have the reels and a camera
BP_PlayerController (type: PlayerController) - for controlling the pawn
BP_SlotMode (type: GameModeBase) - for assigning the pawn and player controller
BPI_Framework (type:BP Framework) - for using it in the future

I have set up the camera to be at a distance from the reels. Used a Fieldview of 25 and aspect ratio of 0.56
Set up the Editor Preferences > Play to use a Portrait mode with a 1080 x 1920 resolution (this keeps resetting on me for whatever reason)

Everything looks ok, until I hit play.
Instead of using the pawn camera that I set up, I am being placed in between the reels. See the last screenshot.
What gives?

Ok, I rebuilt everything from scratch and it seems to position the camera right this time.
However, after implementing the click on the button, nothing works.
I can confirm that by using the “R” key the number generator is outputting a new number every time.
See screenshots below. But on click, nothing happens.

A little more debugging:

I disconnected the Tick Event and replaced it with an “On Clicked”(SpinButton) Event.
Replaced the target from the Spin Button to Reel_1.
When clicking on the button now, it prints a string. However the rotation is not happening :frowning:

Any tips?

A little more debugging… I realized I forgot the “Get world Delta Seconds” before. Plugged that in and no matter which target I choose, roll, pitch or yaw… the reel spins 90 degrees sideways. :roll_eyes:

Good progress, For “Plugged that in and no matter which target I choose, roll, pitch or yaw… the reel spins 90 degrees sideways”:

Seeing zeroes inside of the Rinterp node is a red flag. It’s possible that the asset was created on a different axis, and then the rotation is adjusted in Blueprint, and then it’s getting overridden with that 0 value. The solution to this would be to get and pass the
current rotation values into the node.

I also noticed that the ‘Reel’ assets are inside of the pawn. This strikes me as wrong. (In the same way that writing an entire game in one long code file could be considered “wrong”) Not saying a re-factor is needed, just wanted to point that out.

Are you still having problems with the click? A pawn clicking on itself is a new idea to me so I had to try it out. It worked as intended.

yup, the reels were created in 3dsmax and imported with datasmith. not sure if that is messing the axis rotation. I can try with plain cylinders in UE for now to see if that is the issue. I think the rinterp node was returning 0 because it’s not setting the RollNum variable unless you press the “R” key. which is a separate mapping. How would I go about passing the current rotation values into the node? (As you mentioned above)

K, I rewired the nodes so the Rinterp works on click without having to press a key.

What I have noticed now is that the first time I click on the red button, the wheel tilts -90° on the X axis, but after that all the subsequent clicks work fine… spinning the reel with the random number

This is how I have the reels set up in the viewport:

And this is basically what’s happening when I click the button:

It resets my 90° turn.
Here’s my complete Event Graph so far:

I need a way to tell it that the current rotation should be kept, just add a new rotation on the other axis

hmmm, so after playing with the nodes a bit more, I noticed that if I use “Add Local Rotatio” or “Add World Rotation” it actually works.

This raises a few more questions and hope someone is kind enough to point me in the right direction…

Why does Add work but Set doesn’t? What does it do differently?
Also, I noticed that the Rinterp To works, but it kind of jumps to the random num I’m generating. No animation. I thought it would interpolate that rotation??? Do I need to combine it with a timeline?
Also, How could I link the other 2 reels to work as well.
What I am trying to achieve is:

  1. Each reel should have it’s own rotation set by a random number within a range.
  2. I would like to add a delay, between the reels starting to spin
  3. The duration of the spin should vary a little for each reel.
  4. It would be nice if there’s an ease-in/ease-out for the spinning
  5. Obviously, keep some sort of track of the symbols that the spins land on.(only for the middle row/position)

I know I’m asking a lot, but am not looking for fully working code, just tips on how I could implement those things.

Thanks in advance and have a “Happy New Year” everyone!

:champagne:

For the reels, I see that the static mesh is laying on it’s side by default (and that you’re needing to add 90 degrees in the BP editor) Best case scenario is for the reel to have the correct orientation/rotation with 0,0,0. (You can change this with the in-editor geometry tools now)

Why does Add work but Set doesn’t? What does it do differently?

Add, adds rotation to existing values, set would override everything.

I noticed that the Rinterp To works, but it kind of jumps to the random num I’m generating

In the first screenshot of your last post I see that your interp speed is set to 0, this will cause an instant jump. (try numbers from .5 - 10 )

How could I link the other 2 reels to work as well.

General rule of thumb is that if you’re duplicating code/logic more than 2 times you should put it in a function. But 3 is only one more than two… so you could get away with copy-pasting the same logic without making too much of a mess. Although, be careful: If actively developing it could be a pain to change things in 3 spots.

I would like to add a delay, between the reels starting to spin

You can feed a random number into a delay node.

It would be nice if there’s an ease-in/ease-out for the spinning

Armchair developing here: What if there are 2 stages of rotation, where it will rotate randomly, then once the number/symbol has been landed on, it eases to be centered on the line.

keep some sort of track of the symbols that the spins land on

Having specific range of rotation values that match the symbols seems logical here.