An embarrassingly basic question here, I’m using a static variable as a counter in my class with the expectation that it will be shared among all instances of that class but each class seems to store it’s own version of the variable like a non-static member.
The header file has a variable to store a uniqueId and also a static counter like so:
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = AerialNavigation)
int32 volumeId;
public:
static int32 volumeIdCounter;
and in the implementation I’m incrementing the counter in the constructor and assigning the value to the id to create a very simple counter:
MyClass::volumeIdCounter++;
volumeId = MyClass::volumeIdCounter;
So when I run the code the “volumeId” assigned to every instance remains “1”, i.e each class seems to be maintaining its own version of the static variable.
Any idea what I’m missing? Not sure if my C++ has atrophied so badly from lack of use that I’ve started goofing up even static variable usage
Edit: I did read the posts about using the global singleton class for sharing data in global scope but that seemed like an overkill for what I’m doing here, especially as this is prototype code that I’m just blocking out for testing.