I have my own actor class and a series of ‘building block’ blueprints which I want to add to my actor to build it up based on user input. I think AddComponent is the method I want, however I’m not having much luck getting it to work.
FName TemplateName - I’m not sure what the format of this should be. Should it just be “/Game/Path/BlueprintName”?
UObject * ComponentTemplateContext - I have no idea what this should be. It defaults to the actor class I’m calling this from I think, but I get the impression this should be the class of the blueprint I’m adding… if so, then how do I get that? At the moment I’m just passing NULL.
It runs without error, but nothing appears to happen. No matter what I put for the TemplateName, no error is produced, which leads me to think that it’s just failing silently.
Is this the right approach at all? Does anyone have a working example of doing this sort of thing?
My ultimate goal is to allow my players to create content in the game from a series of building blocks (specifically space ships a the moment). So I have some building block blueprints that include meshes, lights, interactive elements with Blueprint logic, etc.
The player will create then will be able to pilot the vehicle - so I want to be able to apply forces to the vehicle as a whole. I also want to create further building blocks without going into C++ code, and specify which building blocks are available to a player at runtime.
You can create Static Mesh Actors and attach them to a core invisible actor that is the ships’ origin point
Then they will move, rotate, AND SCALE with the core component
so you just move around and scale the core actor, and all attached (at runtime) static mesh actors will follow just as you want
* Attaches the RootComponent of this Actor to the RootComponent of the supplied actor, optionally at a named socket.
* @param InParentActor Actor to attach this actor's RootComponent to
* @param InSocketName Socket name to attach to, if any
* @param AttachLocationType Type of attachment, AbsoluteWorld to keep its world position, RelativeOffset to keep the object's relative offset and SnapTo to snap to the new parent.
UFUNCTION(BlueprintCallable, meta=(FriendlyName = "AttachActorToActor", AttachLocationType="KeepRelativeOffset"), Category="Utilities|Orientation")
void AttachRootComponentToActor(AActor* InParentActor, FName InSocketName = NAME_None, EAttachLocation::Type AttachLocationType = EAttachLocation::KeepRelativeOffset);
#Set Static Mesh
Spawn your static mesh actor (AStaticMeshActor* MySMA)