How to set a SkeletalMeshComponent through C++

I created a custom class which inherits from the “Pawn” class.
I gave it an object of SkeletalMeshComponent.
In my content browser I have a character skeletalMesh.

In runtime how can I set my classes skeletalMeshComponent to a copy of that skeletalMesh?

Hey -

You can use a constructor helper function to get a reference to your skeletal mesh and then use the reference to set the skeletal mesh component. Gameplay Classes in Unreal Engine | Unreal Engine 5.1 Documentation This wiki page has information that should help with setting up and using constructor helpers.

Cheers

those “Asset Referencing” scenarios are very clear and helpful. But how about the function “LoadObject<>” isn’t that a proper way of referencing an asset?

like if I was not creating an object with a hard coded model. I would not hard code it in the constructor.

Wouldn’t I else where when I create this new class object fill out its skeletalMesh data there?

Example:
Player has selected that the ball they want this match to be the spikey ball.
You wouldn’t create a new class for the spikey ball if it worked identically to all the other balls besides the fact its a different mesh. So in this case wouldn’t you just create your “Ball” object then update its skeletalMeshComponent skeletalMesh reference by setting it to the return object of "LoadObject<“SkeletalMesh”>( “Asset/Ball_SkeletalMesh”);

Or am I thinking about it incorrect or an improper approach.

The constructor helpers are mainly used for setting up the defaults of a class or derived blueprint. If you’re trying to set a skeletal mesh at runtime, using FindObject or LoadObject may be a better choice depending on if the asset is already loaded or not. For more information, this documentation page talks about using LoadObject() and FindObject(): Referencing Assets in Unreal Engine | Unreal Engine 5.1 Documentation

would this also work for making an instance of a skeletal mesh? or would FindObject, LoadObject always return the same reference?

In the call to LoadObject you specify the path where the asset to load is in the project. You can make multiple calls, each time indicating a different blueprint or other asset in the project to be loaded.