Dear experts,
I am dropping an item (weapon) with C++ and that looks like this:
void AAdventureCharacter::DropWeapon()
{
if(EquippedWeapon)
{
FDetachmentTransformRules DetachmentTransformRules(EDetachmentRule::KeepWorld, EDetachmentRule::KeepRelative,
EDetachmentRule::KeepRelative,false);
EquippedWeapon->GetItemMesh()->DetachFromComponent(DetachmentTransformRules);
}
}
But when I check in view mode “collision” I see the sphere and collision box of the item are still attched to the Character. And the weapon is still attached to the Character:
Somehow DetachFromComponent
does not work properly - please help me - what am I missing?
You call DetachFromComponent on your ItemMesh not the equipped weapon. So what happens is you detach the ItemMesh from its parent not the actor from your Character.
If you want to detach the actor i think you call the AttachToComponent or AttachToActor function on the equippedweapon and attach it to nothing.
But i recommend to destroy the current weapon and spawn a new one instead on the ground.
1 Like
thank you. That sounds good. I was not sure if there is another way, but destroying and respawning the weapon again makes sense. DetachFromComponent
only detaches the Mesh, makes sense, my screenshot shows it too. Thank you!
Hello, I found an even better solution. I made the static mesh the RootComponent
and now DetachFromComponent
detaches the equipped weapon including the collision spheres.