Spawn point for projectiles

Hello,
I’ve bring trying for a few days to get projectiles to spawn from the muzzle of a gun in a top-down Shooter, which is a component of the pawn. Im able to the projectiles to shoot from the pawn, but it looks like the projectiles are coming out of the characters chest. Should I create some sort of spawn point and attach it to the muzzle?
I tried finding the weapon using c++, but finding components of a pawn doesn’t seem possible.

When you spawn an actor you can specify a Transform (its initial location, rotation…). If your gun has a socket at the end of the barrel, use that o find the world location of that socket. Use this position to create the spawn transform (rotation can be same as the Player itself). Later when you spawn the projectile actor, use this transform

Im able to get the socket location from the Pawn using Mesh->GetSocketLocation, but how to I get the socket from a mesh component of another mesh?

Eitehr you make that component public and access it from the other blueprint. Or you could simply write a public function in your Pawn blueprint which will return the socket location and call it from the other BP.

Hmmm, I must be missing something, I don’t have a blueprint of the rifle, only of MyCharacter, which has the rifle attached to the mesh as a component.

Ooops!

Sorry, I was reading some BP related stuff and that came out wrong. What I meant by BP is ‘Class’ in C++.

So If i understand correctly, your Pawn has a Gun as its component. right. My question is is it a Child Actor Component OR simply a Skeletal Mesh?

If its the later, you might be doing the firing logic within your Pawn class. In this case, you have full access to the Gun Mesh Component and can easily get the socket location.

On the other hand, if your Gun is attached as a child actor component and the firing logic is within the Gun class, you can still get the socket location, because the Gun’s mesh is one of its components.

Your question: "how to I get the socket from a mesh component of another mesh? ".

I am not sure I understand that.

Did you mean: "how to I get the socket from a mesh component of another actor? ".

Yes, so in MyCharacter blueprint, under the Native SkeletalMeshComponent that is my character mesh, I have the Rifle as a SkeletalMeshComponent. I’ve been trying to access the rifle through the Pawn in the C++ code, but am not having much luck.
So are you saying that if I attach a socket to the rifle’s skeleton, that Mesh->GetSocketLocation(“socket_on_rifle”) will be seen? Mesh being ACharacter::Mesh

No you must get a reference to your Gun’s skeletal mesh. You might already have a variable in your Pawn class which holds this. (when you create a Sub component using PCIP.CreateDerfaultSubPbject…, you are assigning the result to a variable.). Using that variable, you can access the Gun’s skeletal mesh and find out the sockets location.

Maybe thats what Im missing, I attached the weapon to the Character in the myCharacter blueprint, in the editor, so I dont have a reference to the weapon in the c++ code. I originally tried attaching the weapon using c++ code, but that didnt workout too well, so I manually added via the editor.

So you create and attach the weapon’s skeletal mesh component from Blueprint? In that case it wont be accessible in C++ (becuase the BP is a new class). So you will need to add the logic in Blueprint itself.

OR if you know how to iterate through all sub-components in an Actor, perhaps you will be able to do that in C++ itself. But that sounds very complicated and might give you a lot trouble later on.

So Either create and attach that component in C++ itself, or move your firing logic to Blueprint