Hi all,
I get the references of game instance by using GetGameInstance() func. When I debug it I saw the packet information in cpp. But I don’t figure out how can I get one bool variable in game instance. In blueprint I cast from game instance and get the value easily but how can I read from cpp?
Which variable are you looking for? Is it on a custom GameInstance subclass? Is that subclass a C++ subclass of a Blueprint subclass?
Yes Gameinstance is custom. I create one and name is gameinstance_widget. My variable is just one boolean value. In one level I create main menu and I have to click one button if user click button 1, that value turns into true otherwise it should be false. So I want to read that value from my cpp file. That cpp file control something in different level.
If you creates your GameInstance variable in blueprint, your variable is inaccessible in C++ code (unless using an overriden getter from C++ code). If you made your GameInstance in C++, you can just call GetGameInstance with a cast and access variable as usual.
I don’t know how I make Gameinstance in C++. If I make it in cpp, could I reach in Blueprint? and can you also give me more info about overriden getter from c++?
You create it the same way you create other C++ classes:
Tools > New C++ Class > All Classes and type Game Instance ( to inherit from it ).
If I make it in cpp, could I reach in Blueprint?
Yes.
and can you also give me more info about overriden getter from c++?
You can just add:
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MyGameInstance)
bool bMyValue = false;
or more fancy:
First of all thank you for your interesting. I create MyGameInstance as you describe and create bool (ex: bool bvalue)in that MyGameInstance.h and I reach in Blueprint. But I want to reach bvalue in my one of the Plugin’s header file. So I #include “MyGameInstancepath/MyGameInstance.h” but I get Cannot open include file “MyGameInstance.generated.h” no such file or directory error. This error line is in my instance header. If I didn’t include in plugins that line execute and didn’t give any error. Just give me error when I try to include MyGameInstance.h file. Do you have any suggestion for that problem ?
I just change the game instance’s folder path into my plugins file and I include it. I reach that variable thank you for your help everyone.
You probably forgot to add your game as a dependent module in the Plugin, but that’s not a good practice anyway.
Plugins are usually for reusable code across multiple projects.