How to access singleton instance

Hi! I am super super new to Unreal(been using it less than a month). I am used to Unity and everything here seems super different. Anyways I can’t figure out or even seem to find online how to access a singleton object.

I did everything from the tutorial on this

I also don’t understand blueprints at all and couldn’t seem to figure out how to get the target node shown in the picture on this link. I am going to need to access items I will be storing in my singleton from both C++ and blueprint. Please help.

I can’t tell you why you can’t access your game singleton but to save you some time and headaches you should know that you should be using a game instance class instead, see Game Instance VS Singleton - C++ Programming - Unreal Engine Forums for the differences and why the game instance is preferred.

Getting your game instance from blueprint is simple, there’s a built in “Get Game Instance” node that you can use, then just cast it to your UGameInstance derived class.

If you make a child class of your C++ GameInstance in Blueprints then any variables you mark as a UPROPERTY with the EditDefaultsOnly or EditAnywhere flag will be editable from the BP class. You’ll have to turn “Show Inherited Variables” on to be able to see them from the Blueprint editor.

Marking UPROPERTYs with “BlueprintReadOnly” or “BlueprintReadWrite” lets you access/access and edit them at runtime.

Is there any way to have the variables for the game instance show up in the editor somewhere? I need my variables to be able to be set in the editor and accessed in several different c++ classes and blueprint scripts at runtime. I made my class derive from UGameInstance and included Engine/GameInstance.h. i selected in the game manager drop down in project settings under map/mode , but couldn’t see any of the variables to set.

How can I access those variables in other C++ classes? I followed the tutorial at this link

but it says my class is not defined when i try to cast return value of GetGameInstance into my custom game instance. I also am unsure of how to access it in Blueprint. i can get the node to get the game instance and the cast node to my custom game instance but I can’t seem to get the target node to access my variables in there. i’m super new to Unreal and I don’t know anything about blueprints really, unity doesn’t have visual scripting. Was trying to maybe do something like the answer give at this link

but can’t seem to figure out how to get the target node or any kind of set/get nodes for my specific variables in the blueprint of my game instance.

The only reason I can think of that it would say your class is undefined is that you forgot to #include your custom GameInstance’s header at the top of files you’re trying to use it in. If you’re already doing that then can you copy/paste the errors you get when you compile here?

I’m not really sure what you mean by “target node” in your blueprint, can you post screenshots of what you have set up so far?

I can include the game instance header but if the variables can only be modified from the editor via blueprint I need those variables. The modified/set ones. Can I not access those in C++? I tried typing the name of the blueprint class .h in the includes but it doesn’t seem to have a header unless I have the name wrong. And by target node I mean the node in this picture that says target on it pic

Oh, C++ can’t see variables and the like declared in blueprint. Anything that needs to be modified in code has to be declared in code as well.

For the blueprints, you’d just need to drag off the “As Krysta Instance C” pin in that screenshot and search for Get/Set to get the nodes you want. variables declared in your BP class should be there by default, any declared in C++ need to be BlueprintReadOnly or BlueprintReadWrite UPROPERTYs.