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"

C++ static variable not initializing.

I'm having a problem where it seems static variables initialized in the top of the .cpp file are not initialized properly.

ItemFunctionLibrary.h:

 UCLASS(BlueprintType)
 class MYPROJECT_API UItemFunctionLibrary : public UBlueprintFunctionLibrary
 {
     GENERATED_BODY()
 private:
     static bool s_initialized;
 public:
 
     UFUNCTION(BlueprintCallable, Category = "ItemFunctionLibrary") static bool LoadItem(const FName itemID, UItem*& itemOut);
     static void Initialize();
 }

ItemFunctionLibrary.cpp

 bool UItemFunctionLibrary::s_initialized = false;
 
 bool UItemFunctionLibrary::LoadItem(const FName itemID, UItem*& itemOut)
 {
     if(s_initialized == false) // s_initialized is always TRUE
     {
         Initialize(); // never hit
     }
 
         // other stuff
 }
 
 
 void UItemFunctionLibrary::Initialize() // entire function is never called
 {
     s_initialized = true;
     // other stuff
 }

I'm not sure what I'm doing wrong. I've used this version of initialization in other C++ programs before, but it doesn't work in this version.

Product Version: UE 4.11
Tags:
more ▼

asked Oct 27 '16 at 09:25 PM in C++ Programming

avatar image

Yulgalminakf
73 12 18 27

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

1 answer: sort voted first

For anyone who cares, I found the problem. The problem was that when the engine hot-reloaded, it didn't load quite right. It seems to be an on-going issue with the engine, with understandably little hope for fixes in the future (it's a very complicated problem to work out on the fly). The work-around is simply closing and re-opening the engine.

more ▼

answered Dec 18 '16 at 06:24 AM

avatar image

Yulgalminakf
73 12 18 27

(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