Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Why can't I add time to my FDateTime variable?

I'm trying to build a very simple in-game clock and calendar by using a FDateTime variable to hold the game world's date and time. In order to increment the in-game clock correctly, each tick I multiply DeltaTime by the game time/world time ratio; if I want 2 seconds to pass in-game for every second in real-life I multiply the delta by 2, if I want a full minute to pass for each real-life second I multiply it by 60:

 float adjustDelta = DeltaTime * gameSecondsPerWorldSecond; //convert real time into game time
 dateTime += adjustDelta; //Add the adjusted delta to my FDateTime variable
 debugSec = dateTime.GetSecond(); //Drop the HH:MM:SS values to public variables so I can monitor their value in the inspector
 debugMin = dateTime.GetMinute();
 debugHour = dateTime.GetHour();

This compiles cleanly, but when I run it and view my debug floats in the inspector, all three remain at 0 and never increment. My assumption is that the mistake lies in trying to add a float to an FDateTime, but since the compiler didn't produce a type mismatch I'm not really sure what I should be changing to properly increment time.

Product Version: UE 4.10
more ▼

asked Jan 30 '16 at 05:53 AM in C++ Programming

avatar image

251 97 67 83

avatar image BrUnO XaVIeR Jan 30 '16 at 07:26 AM

You have to construct a new FDateTime and do

dateTime += NewDate.

And FDateTime members are int32 data, adding adjustDelta won't do anything.

avatar image HInoue Jan 30 '16 at 07:35 AM

Hmm okay... how would I manually add seconds/minutes/whatever to NewDate, to ensure I'm not just adding a blank date to my existing one? Playing with intellisense shows me getters for each individual field, but I can't seem to find setters.

avatar image HInoue Jan 30 '16 at 11:06 PM

I just wanted to add, apparently you can't actually add FDateTime like this; the following produces an error, "no operator found which takes a right-hand operand of type FDateTime":

 FDateTime modifyTime(0,0,0,0,0,0,DeltaTime);
 dateTime += modifyTime;
avatar image HInoue Jan 31 '16 at 12:05 AM

Okay, so I figured out that I'm supposed to use a timespan instead of adding two DateTimes, but that still doesn't seem to work with deltatime; the following never advances the seconds, minutes, or hours:

 FTimespan modifyTime;
 dateTime += modifyTime;
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first
 modifyTime = modifyTime.FromSeconds(DeltaTime);
more ▼

answered Jan 31 '16 at 12:54 AM

avatar image

251 97 67 83

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question