Let’s say you get all actors of a certain class from your level, and you want to store some of their variables in a SaveObject.
Is there a way to store those variables in some kind of “container”, like a structure, that doesn’t have those variables defined yet?
Basically, the “container” doesn’t know what will go inside, until you fill it.
basically i would say use a custom struct - but you need to have the variables type prepared in the struct before setting it… maybe there is an option to “create new variable” in a custom struct i do not know of.
What types of variables are you going to be storing? Are you going to know the variable types before you store them? If you at least know the types you could just store them in an array, or map. For example, have a map where the key is the name of the actor, or even a reference to the actor itself if needed, some identifier to know where the data belongs or what it came from. Then the value could be a struct with all the data you want to be able to possibly save, or just a single value if you only need to save one thing, i.e. a float or string.
If you don’t know the type then you can do some things like that via C++ and utilize some of it via blueprints depending on what you’re doing. Though if you don’t know the types then you’ll want to make sure you have good ways of handling the data later when you need to retrieve it.
there’s tvariant you might use it on a struct, on cpp. but you won’t be able to expose directly to bps.
you can still somehow expose it through some custom functions
To add on to the other suggestions, it’s probably unlikely that you’ll need to keep your variables completely undefined. If you’re trying to do something like save a bunch of unknown blueprints, you can likely just define an Actor type which accepts any blueprint actor (or for that matter any actor)- though if you want to do any modifications specific to the blueprint, you’ll need to cast to that specific class, which would not be great at a large scale.