Problem attaching component to actor socket

I have an AActor, and a component with the following code attached to said actor. I’m trying to spawn a point light, then attach that light to a socket I’ve already created in the actor’s hand:

UPointLightComponent* PointLight = CreateDefaultSubobject<UPointLightComponent>(FName(TEXT("TestLight")));
AActor*	myActor = this->GetOwner;
PointLight->AttachTo(myActor, "RightHandHB_Socket");

However, the last line produces an error, “Cannot convert AActor to USceneComponent”. I assume that means that instead of myActor, it wants a component or property of myActor, but I can’t figure out what constitutes the scene component; what reference should I be feeding to AttachTo instead of the actor itself?

actors don’t have sockets, meshes have sockets. so your actor probably has a skeletal mesh component which has the socket.

scene components are any component that has a location, so any type of mesh, light, decal, camera, collision volume, etc… would be a type of scene component.

So what’s the correct way to locate a child component of an actor? I’m checking the contextual popup for myActor->, and I’m not seeing anything resembling a skeletal mesh (which I know is there), would I want to cast myActor as a mesh, or myActor->GetComponentByClass?

where did you set up the “RightHandHB_Socket” ?

I manually placed the socket on the skeletal mesh in Persona, then set the Mesh field in the ThirdPersonCharacter blueprint equal to that mesh. (This is the blueprint from the Third Person C++ example project). The model correctly runs animations that only work for the mesh in question, so I’m 99% sure it’s on the model.

if its based on Character, it will have a function called GetMesh(), which will return a reference to the skeletal mesh that owns the socket.

something like this:

 UPointLightComponent* PointLight =  CreateDefaultSubobject<UPointLightComponent>(FName(TEXT("TestLight")));

 ACharacter*    myChar = (ACharacter*)this->GetOwner;

 if (myChar != nullptr)
 {
   if ( myChar->GetMesh() != nullptr)
   {
      PointLight->AttachTo(myChar->GetMesh(), "RightHandHB_Socket");
   }
 }

That works perfectly, thank you!!

Am I correct that (ACharacter*)this->GetOwner; is just shorthand for Cast(this->GetOwner)?

yeah, i meant:

ACharacter*    myChar = Cast<ACharacter>(this->GetOwner() );

Awesome, thank you again! :slight_smile: