This seems to be a basic issue, but I can’t find help with the specifics of it, which revolves around setting up the hierarchy of components on my weapon class. Current setup is as follows:
Skeletal mesh as root.
Collision component as child.
Muzzleflash (scene component) as child
Audio component as child.
Skeletal mesh has physics turned on when not picked up, so the weapon behaves properly and gets tossed around when forces are applied.
Linetraces also function correctly for pickup by hitting the collision (box) component. Physics is turned off before attaching to actor component.
My issue is that I can’t adjust the weapon mesh in the skeletal mesh component, as in orient it or transform it, as it is the root. When I try to add a scene component as root above the skeletal mesh I can edit the skeletal mesh, but it messes up the physics in-game. The weapon drops due to gravity force and the scene component (the root) stays put in world space, which is to be expected. Also the skeletal mesh is not able to be attached to actor component on a character, only the scene component as root gets attached to the character.
Clearly I understand that everything is behaving as it should, but that I am not setting it up correctly for the desired outcome.
Am I suppose to edit the orientation, transform and scale of the weapon mesh somewhere else and in the hierarchy keep it as skeletal mesh root, or is there another way this is suppose to be setup?
EDIT: I noticed that in the skeletal mesh import settings, things like rotation, scale and translation can be modified and the mesh reimported. Is this the correct way of adjusting a skeletal mesh that is also the root in an object?
Scene component, then all the rest so you can modify transforms etc. You’ll have to keep moving the root on physics rest and adjust the mesh to the new position/rotation.
Realistically you’ll want to create a static mesh of the weapon that gets tossed around via physics. On pick and attach you destroy the sm variant and spawn the sk variant.
You Skeletal mesh variant will need to have a scene component as root.
Ok gotcha on the scene component and the two variant spawn despawn method.
Edit: I’m still running into the same issue. The Skeletal mesh does not get attached to the actor component (NPC), only its root component (which is a scene component) does. The skeletal mesh just spawns and just stays put at world 0, 0, 0.
Physics and collision is turned off.
EDIT 2: Not sure if I am experiencing a bug. When I set the skeletal mesh physics and collision off in the blueprint by default and then run the game, the weapon spawns and properly gets attached to the socket. When I set the skeletal mesh physics and collision on by default, then run the game and spawn the weapon, set its physics and collision off and then attach it to actor component, it fails.
So it seems there is some issue with spawning it and setting its physics and collision off during runtime that is not working as intended.
EDIT 3: Nvm, the work-around method you suggested with swapping works.
When spawning weapon on NPC, spawn the skeletal mesh with physics and box collision turned off by default in parent blueprint class, as they are never needed to be on.
When weapon is dropped, swap it with the static mesh variant that has physics and box collision turned on, so it fall correctly with gravity and respond to physics events in the world. Thanks.