Hi, I’m just wondering if there’s any way that I can easily get an object instance of a C++ class I’ve created. Basically I have a few different C++ classes (which I’ll call “actions”) all as children of another class (“actionbase”), and I’d like to use them as object instances instead of as classes. At the moment, I’m using TSubclassOf to get an array containing each of the action classes, which I want to use via blueprint to get the values of their variables, however as is shown below, this returns an array of classes, not instanced objects as I’d like.
I’ll be using these “actions” on a few different actors so creating new objects at runtime for each of the classes won’t work as that’d create multiple instances of the class, which I’d like to avoid. If anyone knows if there’s a simple way to do this I’d appreciate the advice. Alternatively, if there’s a simple way of creating and loading a list of action objects before runtime with it being usable in C++, that’d also work. Thanks!
Perhaps you are looking for DataAssets? You can define the Data Asset class in C++ and create instances in the Content browser with the Property values you want at load time.
This Actions class is an AActor? Or ActorComponent? If you’d like to get all the actions instances of the level (and they’re actors) , I think a GetAllActorsOfClass node will work.
Building one class per … thing … isn’t how the engine works. And, in general, if that’s what you need, why wouldn’t you use global functions instead?
The best way to accomplish what you want, is to create an instance of each of your classes, and keep those instances somewhere convenient, and then talking to them. (Make sure they are properly marked with UCLASS() and UPROPERTY() decorators to support blueprint access!)