I have a class which contains a variable, which is a TSubclassOf, and I’m setting this variable in blueprints. Now, I need to know how to make a component of this specified class
I have an actor component that will be used as a base for some other components, and these other components will be used for their own respective characters. How could I approach this in c++? My current thought is to make a TSubclassOf for my character class, which would then be set to their respective component in blueprints, and from there make a component of that class in c++. But how can I do this??
Well, I have a base class for each type of component (like inventory comp, status comp, etc.). From those I can create child components in blueprint. What I need is to assign these child component classes to a variable in c++.
Yes, I am already. This way I can assign my child components to their respective actors, but now the next step is to create them, just like you create components with CreateDefaultSubobjects. But how can I use this assigned component class, and create a default subobject or create component from class??
To create a component at runtime you need to call NewObject
MyComponent = NewObject(this, MyComponentsClass);
if (MyComponent)
{
//Setup attachement here
//This will register the component with the actor supplied in the Outer (the 'this' in the NewObject.
MyComponent->RegisterComponent();
}