x

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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Blueprint communication with static class

I'm trying to make an in-game clock with its own time-passing speed, ability to fast forward, etc. and all animations and day/night cycles and the like would adhere to it. Since this is a one-off system, I decided to make it a static function library.

I want to be able to grab its properties (ex. current time) and display it on the HUD. However, nothing shows up when I attempt to search for my supposedly exposed variables. How should this be properly written?

Current .h:

 UCLASS()
 class UGClock : public UObject
 {
 public:
     GENERATED_BODY()

     static void Setup();
     static void FastForward();
 
     UPROPERTY(BlueprintReadOnly)
     static float CurrentTime;
 
 };
Product Version: UE 4.7
Tags:
more ▼

asked May 19 '15 at 06:52 AM in C++ Programming

avatar image

sgp
166 32 41 56

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

Static functions work, lack of static properties support is lack of UE4, but C++ is fully functional, so you can make get and set functions for those static variables. Also note as static properties don't in reflection system, garbage collection won't work on, so you need to watch out what you do with them

more ▼

answered May 19 '15 at 04:18 PM

avatar image

Shadowriver
36.6k 930 169 1111

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hello, sgp

Please note that static properties are not available in UE4, but there are Game Mode and Game State classes that are more suitable for global parameters of your game.

However, there is a possibility of creating your own static libraries. If you like to learn more about this, please go here:

https://wiki.unrealengine.com/Static_Function_Libraries,_Your_Own_Version_of_UE4_C%2B%2B,_No_Engine_Compile_Times

Hope this helped!

Good luck!

more ▼

answered May 19 '15 at 12:49 PM

avatar image

Andrii Melnyk
1.8k 60 19 112

avatar image sgp May 21 '15 at 03:08 AM

Thanks, the GameState class seems to be what I'm looking for, but I'm lost on how to actually work with it and can't find anything to help me. Are there any tutorials on this?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Also you can create a Blueprint like in https://wiki.unrealengine.com/Blueprint_Function_Library,_Create_Your_Own_to_Share_With_Others

These are static function you can then call you other statics from that.

more ▼

answered May 19 '15 at 04:01 PM

avatar image

SND R Keene
963 31 118 113

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

To use the GameState, tell Unreal to make a new C++ class in the project. Make GameState be the parent class.

Now you have a C++ ( .h and .cpp ) of your new GameState, like MyGameState.cpp and such.

Then in your project set the new class as the game state instead of the default game state.

Make usre to generate the Visual Studio project, compile etc.

Now in MyGameState.h you can add new functions to call. They are not static but can call static calls. You can also access them from blueprints if they have the annotations above the function calls.

more ▼

answered May 21 '15 at 04:43 AM

avatar image

SND R Keene
963 31 118 113

(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