I’m wondering if it is also possible to have static variables/properties? More specifically I am trying to have a static TArray that stores all instances of my class.
All methods I’ve attempted result in no build… is there a UE4 way of doing this or is it simply not supported?
Static objects is C++ feature, there is no way it can’t be supported. Some pieces of custom libraries may not work with static objects though, reflection for instance.
I’m not sure if static UPROPERTY would work actually, i have not tried it.
I will try those things. However, as far as wanting static… I suppose it’s because I can’t imagine why it would be defined in the instance of any class.
To get into my code more, I have created a static library like the one in this other tutorial:
Inside of my library, I’ve created a helper function that wraps up the spawning of certain actors, calls a function on the actors and (hopefully) adds those actors to an array. I was hoping to have that array exist in the library (and therefore be static) such that I can access the array from other places.
You can make a static function to access the instance of your class that is storing your data
But you will need to instance something, if you want to dynamically change the data during runtime!
Static stuff by definition can’t change during runtime, so you can’t spawn stuff and then add it to a static array, that’s all runtime activities requiring a runtime instanced dynamic array.
Epic had posted a tutorial on the topic of loading assets during runtime but I can’t seem to find it… I’ve already stated my preferred method of storing things in a Blueprinted Player Controller
Oh wow that’s awesome, I will do a wiki on this soon as I set it up on my end
Thanks Michael!
EDIT
Michael has this feature been removed? I can't find it in BaseEngine.ini, or in Project Settings->Engine->General
EDIT 2
I do see it in the source code for Engine.h, but the fact that it is absent from the Project Settings menu makes me wonder if it is being phased out somehow?
EDIT 3
Nvm it was hidden under "advanced" properties, God I wish that thing did not exist, and I wish there was a way to always see all properties.
Rama
In particular the answer that I posted to my own question. I’ve tested this stuff in the editor and it all works fine. It also seems to correspond to how the word “static” is used in general C++. However, having just come across this convo, I’m wondering if my solution is going to fail after cooking or something. Is the static keyword different in UE4 than in general C++?