1
\$\begingroup\$

I'm making a 2D sandbox tycoon in UE4. I haven't started the money system yet, but I was wondering how I could make a money system that gives you a certain amount of money per real-life minute. Then, I want to connect this system up to some text so that the digits go up by whatever amount each minute.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ What is your actual problem? The "getting money every minute" or do you also want to do this when the user is not playing? Please clarify \$\endgroup\$
    – codewing
    May 6, 2019 at 7:03

2 Answers 2

3
\$\begingroup\$

If you only want to do this while the game is running you can use the timers the engine provides.

Here is an example from the docs.

Brief summary (Current UE Version 4.22):

  • Create a method which should be called after the timer ends (e.g. rewardCallback)

  • Add a Blueprint node called 'Set Timer by Function Name'

  • Set the function name in the blueprint node to be the name of the method created in the first step (i.e. rewardCallback)

  • Adjust the other parameters to your needs

  • Make sure the node gets called at least once (or more often if you don't loop the execution of it)


If you want to extend it such that offline time also gets taken into account then you might want to simulate the time the player was away.

E.g. In an extremely simple case:

Delta_away = time_now - last_logoff_time //in minutes since 1970
Reward_away = reward_per_minute * Delta_away 
\$\endgroup\$
0
0
\$\begingroup\$

Unreal offers several built in timers and, depending on your needs, I'd suggest either GetTimeSeconds and GetRealTimeSeconds. Both do the same job but GetTimeSeconds gets paused when the game is paused whereas GetRealTimeSeconds does not.

Unreal Links:
GetTimeSeconds
GetRealWorldSeconds

You'll need to set up two more variables. One to compare the time since money was last added (reset every 60 seconds or however often you want more money added) and a value for the total money.

HUD's are hard to explain in writing so I'd suggest finding a YouTube (or similar) video but essentially, create a HUD Blueprint (found in Add Blueprint->User Interface->Widget Blueprint) and add a Text (or Text Block) to your creation. In the details tab, where you enter what text you want, you'll see a button labelled "Bind". Click this and select "Create Binding".

Inside the binding, you now need to CAST to wherever you set the money variable and hook the output node up to the money variable. Unreal should convert it to Text automatically but you might need to do this yourself.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .