First post here, hopefully i can get some help resolving an issue(s). Apologies, if i sound like a beginner just started learning. Would appreciate any guidance
What i’m trying to do:-
I made a toolbar button to run this tool for now. I have a bunch of static mesh assets in my project. I’m trying to create a blueprint of actor class where i want to add a few static mesh component slots, add my static meshes in there and set a relative location for each static mesh that has been added.
I’ve so far been able to create the blueprint,and add static mesh components, just having trouble figuring out how to connect the static mesh components to the static meshes, and set their location, inside the blueprint.
Assets are located at /Game/Assets/TestAsset1,2,3…
On a side note when i try to create a UStaticMeshComponent using CreateDefaultSubobject, it keeps saying its undefined even though i have #include “Components/StaticMeshComponent.h” . What iam i doing wrong in this scenario?
CreateDefaultSubobject is what is called a template function in C++ meaning you have to supply the parameters that the template expects so the compiler can generate the actual function. This particular template simply wants the typename of your component as template argument which in practice looks like this:
To make your life easier, you can get the path in the exact format that FObjectFinder expects by right clicking on your mesh in the asset browser and selecting ‘Copy Reference’.
This is super helpful, I realized a couple of things that i had not paid attention to previously.
CreateDefaultSubobject , only works inside constructor, apparently NewObject is the way to do it outside the constructor.
FObjectFinder is also limited in scope to the constructor, so I had to use :-
StaticLoadObject(UStaticMeshComponent::StaticClass(), NULL,TEXT(“StaticMesh’/Game/Assets/TestAsset1.TestAsset1’”));
So no errors, but StaticLoadObject keeps giving me a warning
LogUObjectGlobals: Warning: Failed to find object ‘StaticMesh’/Game/Assets/TestAsset1.TestAsset1’
But I am not sure this would work for you either. Looking over your question again now I am not even sure what you are trying to do. Are you developing an editor plug-in or is it just some excercise? Where and how are you calling this code?
Also StaticLoadObject expects the fully qualified path if you don’t give it an outer.
You can use a weak object pointer just like a normal one but don’t use it without checking if it is nullptr first because it doesn’t keep the object it points to from being garbage collected.
You are absolutely correct, i’m doing a terrible job of explaining what i’m trying to do.
So I made a toolbar button plugin that when clicked. Grabs a bunch of assets in a folder along with some transforms i’m supplying and assembles all those into a blueprint actor. Something similar to a prefab in unity.
So as i read and understood more i learnt:-
The USCS_Node that i’m using to add the component like
RootNode->AddNode(NewNode1); // Where the RootNode is the root node of the newly created blueprint
This doesn’t actually add anything till i call CompileBlueprint() from Kismet. So i have 2 options :-
Figure out simple construction script way of setting transforms.
Compile the blueprint, then grab it as a UBlueprintGeneratedClass and parse through the components and set transform.
Looking into first option now :).
Thank you again for your time and patience, seems like the first thing i need to do is know how to ask the right questions :). I did it this toolbar button method to figure out how to do it and create 1 blueprint actor so that i can run it and test the process. Is there a better way to test code when you are working/learning?