Hello everyone!
I am having an issue figuring out where to go from here with my code. I am spawning a weapon, and trying to attach it to an actors Skeletal Mesh Component.
I have an Actor Component called AC_WeaponHandler that is a child of my actor.
AC_WeaponHandler.cpp:
AActor* WeaponActor = GetWorld()->SpawnActor(Weapon); //Gets Weapon Reference
AActor* ActorRef = GetOwner(); //Gets Actor Reference
TArray<USkeletalMeshComponent*> SKMesh; //Creates Skeletal Mesh Array
ActorRef->GetComponents<USkeletalMeshComponent>(SKMesh); //Appends Skeletal Mesh Array SKMesh
WeaponActor->AttachToComponent(NEEDMESHHERE,FAttachmentTransformRules (EAttachmentRule::SnapToTarget, true), "weaponSocket"); //Attach Weapon to SKMesh Socket
I know that I cannot directly access the mesh from the array and it needs to be specifically assigned to a variable, and then passed to “NEEDMESHHERE” However the syntax for AttachToComponent() requires a USceneComponent and not a USkeletalMeshComponent. When I pull the mesh from the array, how can I convert it to a scene component? Or am I going about this all wrong? I have been researching this for a day and most of the ‘solutions’ I found did not work, as the syntax must have changed since when the solutions were posted. I have come to the above code mostly by looking at the code from within the definition in VS. Also I am relatively new to C++. Been messing with it on and off for a few years.