[QUESTION] Apply Static Mesh to StaticMesh component

I’m sure it’s accomplished by the SetStaticMesh(UStaticMesh *NewMesh); function.
However, I’m not sure how to get the static mesh reference of the mesh from my content browser.
Thanks.

That’s easy!

#C++ Constructor

Right click on your static mesh asset and select “Copy Reference”

Than paste into code in constructor

AJoySMA::AJoySMA(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
//Mesh
static ConstructorHelpers::FObjectFinder<UStaticMesh> StaticMeshOb_torus(TEXT("StaticMesh'/Engine/EditorShapes/Meshes/Shape_Torus.Shape_Torus'"));
if (StaticMeshOb_torus.Object)
StaticMeshComponent->SetStaticMesh(StaticMeshOb_torus.Object);

or

#Blueprinted Class Property

#.H

create a blueprinted version of your class, and make a UStaticMesh* so you can assign the static mesh in the editor.

The value set in BP should only be accessed after PostInit.

/** SM Asset for Player Starts */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=StaticMeshAssets)
UStaticMesh* AssetSM_PlayerStart;

Thanks!? It works!
Where did you come across this? I need a great reference.
Furthermore, how would I get the position of the static mesh component?
I’m only struggling with the API. Steep learning curve, haha.

Dear Skydive,

please post each of your questions as a separate thread for easier searches for future users.

I can then answer them :slight_smile:

I’ve been working with UE4 engine for months so I"ve learned a lot on my own :slight_smile:

#I’ve posted many tutorials on the wiki here:

UE4 Wiki

You can read a longer description for the C++ version in Unreal Engine 4 Cookbook in Packt. You can read the first lines here. The books is from 2016 and I recommend it a lot.

Hey darkgaze, from where did you get this book? I tried to find a free pdf on google but I couldn’t. Could you help me?

Do what I did. Pay for it. It’s worth it. I suggest you follow this website: everyday, they give a book for free. Other times books are 5 dollars or something like that. Free Learning | Daily Programming eBook from Packt