How are you supposed to add static meshes to Actors?
In UE3 I did this mostly in defaultproperties. I know that is now done in the constructor, but can’t find an example of it. I looked at the pickups in the ShooterGame but they didn’t do that, they did add collision in the constructor.
I want to be able to spawn from code so don’t want to have to link something in a Blueprint.
but I’ve also done it the fancy new UE4 way and must say it is a lot simpler/faster/less sensitive to assets being moved around in project.
Fancy New UE4 Way
I’ve been informed on multiple occasions (its a great new thing I had no idea about), that you can
simply set up some pointers in your .h file on your base class
and then blueprint that class,
and then set the static mesh / skeletal mesh component properties in the Editor in the Blueprint default properties!
Here’s the code you’d need
/** Skeletal Mesh Comp, Set In BP Default Properties */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=SkelMeshComponents)
TSubobjectPtr RoyalSwordL;
/** Static Mesh Comp, Set In BP Default Properties */
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category=StaticMeshComponents)
TSubobjectPtr AwesomeSword;
Advantages Of this Method:
Much less code and less chance of errors as result
Drag and drop visual interface yaaay
if you change name of assets, the BP will update your pointers automatically
you can get access to the components in BP or in C++ very fast
I heavily restricted access from BP / editor itself as my choice, but you could also use
(EditAnywhere, BlueprintReadWrite) for total access and reading/writing
Note of caution:
Never expect that your pointers are valid, always do the null check, especially during your first compile, before going to set the values in the editor