Can i get some feedback on this?

i’m quite new to visual scripting so try to be descriptive please.

the idea is that: if the player is near a rock, he would get 1 coin per click, but if he was near a gold rock, he would get 2 per click.

it works and everything BUT

i’m thinking later when i’m going to have 20+ types of rocks that i’l be going through 20 loops each click. is that going to affect performance? the player is expected to click 80 times a second (mouse macro).

if you can please have a look at it and tell me how to improve it.

thanks in advance.

Are you new to visual scripting or programming in general?
You could use an enum with rock types. Then instead of doing if statements, you just do a switch on enum.
You could *also * use a data table to just pull that rock types data. So you’d see how much that type of rock is worth which saves on the amount of variables you seem to have and also allow for a central place to modify the values.

https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1ga2b_ZaJoaR5dLHOFw4-MMl/5nLqEW6YXPY/

Maybe you should make a macro or function of the right area. Think it would be easier. And yes, you should create an enum to do a switch on near rock/gold.

Why are you setting float gold to gold and float rock to rock. Rock is already set to rock, and gold is already set to gold?

I made a couple of screens for you on how to switch on enum. Create an enum, add it as a variable in your blueprint. Drag the enum variable into the blueprint, then drag out from the pin and type switch.


Instead of having a switch or if at all, make a base class ‘rock’ that has children silver/gold/copper. Have a float variable called ‘Gold’ on the Rock Actor, and simply change the value whenever you create a new child blueprint of a Rock.

Add an overlap collision to the Rock, and store a variable reference to the Rock on the Player when an overlap occurs. Then when the player left clicks you can call a ‘Get Gold Value’ function from the stored reference. This simplifies your problem so that whenever you wish to create a new ‘Rock’, like platinum, you would create a new child of Rock, and only need to change the value of the Gold variable on the new Rock class to whatever you want.

Just be sure to add an end overlap to set the Rock variable reference to nothing.

I made and uploaded an example project that demonstrates the way inheritance works (with rocks giving gold). It could be improved and is missing AnimMontages, but should give you a great start!

Good Luck!

There is no reason at all to use Switch on Enum if you are just using a different variable for the multiplication. You can just use a Select node, with the option being determined by the Enum value, in-place of the Gold or Rock variable.

thanks guys for all the replies, i managed to get it working with the switch enum method. really appreciated!

oh god i did not even notice that, ****. thanks for the heads up.

No problem :slight_smile: