Need help keeping instance data in my C++ plugin

I’m having trouble with something I’m trying to do in C++.

Basically I have a C++ plugin I’ve created. What I want to do is create an int array (it’s more than that but I’m simplifying for this post) that I want to store and manage completely inside my plugin, with C++ code. Any handling and processing of this array should be done inside C++. I only want one access method that will return a value from this array to my blueprint when called.

I was under the (wrong, I now assume) impression that I could simply add some instance variables and methods to my UBlueprintFunctionLibrary class and then access their values from my blueprint. But now I think I understand that these classes can only have static methods and I can’t store instance variables in them.

Is it possible to do this? I have been searching for a while and didn’t have any luck so far. Any help is appreciated.

Hi jorgebonafe,

What I usually do is have a method in the classes I want to save to convert to and from a string (just comma separated values etc), then either save that string to an AActor Tag, a UAssetUserData class or save it in an ini with GConfig:

(search for “Tag”):

If what you’re looking for is a blueprint function library but with data, you probably want to look into Subsystems. Depending on the subsystem that you create, it’s lifetime will be different. There’s a GameInstanceSubsystem which matches the lifetime of the GameInstance, a WorldSubsystem that matches the lifetime of UWorlds, LocalPlayerSubsystems, etc.

The engine controls when these objects are created and destroyed, but since they’re instances you can have useful instance data on them. The only minor hiccup is that you need a WorldContext object to find the one that you’re interested in if you’re giving it static functions, but for blueprint functions that’s usually not a big deal since there’s markup to hide that sort of input.

1 Like

Thank you so much man, this is exactly what I needed :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.