Need help with weird static variable behaviour c++

c++'s statics will be global for editor and all pie sessions, that’s why your Initialized is true. But also, as you can see:

I start to lose some informations on each of the GridElement*

your GridElement*s are killed by garbage collector since your array isn’t an UPROPERTY() (and iirc you can’t mark static variable as UPROPERTY())

As for solution, i like the answer from this thread: Singleton pattern in c++ - #2 by smugdev - don’t use c++'s singletons and use ue’s local “singletons” from gameplay framework.

all my instances to have the same grid

Depending on exact goals, something like GameMode, GameInstance, GameState or as said in other comment Subsystem - makes sense. You can create a single USharpPattern* (or just an array of UCraftBox’es) here and use it when you create instance of object or whenever you need it.

1 Like