Hi all, I’m looking for a way to return the actor/component placed inside a socket on a skeletal mesh.
ie; is there a node I can use that can get the actor that currently inside a certain socket so that I can cast to it and destroy it, etc.
Right now I have an equipment system where when the player chooses to equip a weapon it spawns that weapon blueprint in their hand socket which contains a static mesh and blueprint key events (Left Mouse Button does an attack animation and Q unequips (destroys the actor)) the weapon blueprint is set to have input enabled to make this possible.
This works really well, except now I have a dual wield kind of system [(shown in this video)][1] and when I press Q to destroy them both it works most of the time except sometimes it only destroys one and ignores the other Q key press causing huge run-time problems to my system when I go to equip something else.
I’d much rather have the key events ONLY in the player character where everything else is, so I could press Q and the player character blueprint would get any components/actors in the sockets and destroy them both… or press left mouse button to get the weapon inside the socket/s and run their attack routine. I read on another answerhub question that this can be done using interfaces but the user didn’t go into anymore detail than that and I can’t figure out how to do this on my own.
So I’m looking for some help creating this particular weapons interface or something else if someone has a better/easier idea to handle the system I have. =)
I’ve already attached actors to sockets, I just want to detach (or destroy) them from outside of their blueprint, to do this I need to ‘get’ the current actor inside of the socket and destroy it, but I don’t know how to get it.
I’ve updated the title of my question so people don’t get confused.
I was able to resolve this using event dispatchers called from my player character and bound inside my weapons. Still, there doesn’t seem to be a way to return which component is inside of a socket, but my system works exactly as I want it to.
The actors attached to a socket are added as children to the Skeletal Mesh Component and are kept in a list called AttachChildren. You can go through the list of children and check to see which child is attached to the socket in question.
Example:
for (auto SceneComp : GetMesh()->AttachChildren)
{
if (SceneComp->AttachSocketName == TEXT("MySocketName"))
{
// we found it!
}
}
Based on the answer TooManyCrashes I would like to go more into detail on how to get the actors (read: any scenecomponent) of a socket:
//Loop through all the sockets of the mesh
for (auto SceneComp : GetMesh()->AttachChildren)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, SceneComp->AttachSocketName.ToString());
//We want to get all children of a specific socket name
if (SceneComp->AttachSocketName == this->HolsterGrenadeWeaponSocketName)
{
//Now we found the socket that we want, so lets loop though all the children of this socket and print out each child's name
for (auto x : GetMesh()->AttachChildren)
{
// we found an actor!
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, x->GetFullName());
}
}
}
Now you can theoretically split the string from reverse so that you end up just having Weapon1_BP_C_538. Then you could try using FindObject to get something out of it. Not sure if this works however.
You are right. I didn’t like the approach as I hit the same issue as you mentioned so I solved it by keeping a separate list of references to attached actors.