SkeletalMesh & C++

I need to use particle system with my skeletal mesh.I tried to use ASkeletalMeshActor class, but i can’t find it in MSVS. How to spawn a skeletal mesh and set it up?

Hello,

In this situation, you can create a custom AActor-derived class and declare a property of USkeletalMeshComponent in it:

UPROPERTY(/*appropriate specifiers here*/)
USkeletalMeshComponent* MySkeletalMesh;

Please note that you also need a property for the particle system component and a particle system to act as a template for the component :

UParticleSystemComponent* MyParticleSystemComponent;
UParticleSystem* MyParticleSystem;

Thus, you can initialize the properties in Actor’s constructor:

MySkeletalMesh = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("My Skeletal Mesh Component"));
   MyParticleSystemComponent = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("My Particle System Component"));

Now, asssuming that MyParticleSystem object is valid, you can set it as template for MyParticleSystemComponent:

 MyParticleSystemComponent->SetTemplate(MyParticleSystem);

Finally, particle system can be attached to the appropriate socket on the skeletal mesh:

MyParticleSystemComponent->AttachTo(MySkeletalMesh, "SocketName", EAttachLocation::SnapToTarget);

If you like to learn more about sockets in Unreal Engine 4, please go here:
https://docs.unrealengine.com/latest/INT/Engine/Content/Types/SkeletalMeshes/Sockets/index.html

Hope this helped!

Have a great day!