Best way to instantiate an Item for the Player

Hey! I was hoping that someone could help me with this matter. I am trying to instantiate an actor in the world and make it follow the camera as if it were a child of the camera. I do not know how to do this, however…I was also wondering what the best way of instantiating an actor is, because the way that I am doing it right now does not seem to work very well. Here is my script:

 /*FActorSpawnParameters SpawnInfo;
    SpawnInfo.bNoCollisionFail = true;*/
    wp.wpPos = FirstPersonCameraComponent->RelativeLocation + wp.wpPosOffset;
    wp.wpRot = FirstPersonCameraComponent->RelativeRotation + wp.wpRotOffset;
    wp.ItemClass = World->SpawnActor<AWeapon>(wp.ItemBlueprint, wp.wpPos, wp.wpRot);
    //wp.ItemClass = World->SpawnActor<AWeapon>(wp.ItemBlueprint, wp.wpPos, SpawnInfo);

However with this script, the item spawns somewhere in the middle of the level and not really at the relative location of the camera (I set wpPosOffset and wpRotOffset to zero for testing purposes). In the shootergame example, they use “FActorSpawnParameters”, but I have no idea how to implement it because I always get errors. I really appreciate any type of insight that would help me with this. Thank you in advance for any contributions!

The problem with your script right here is that you are obtaining the relative location of your camera component.

Say, if the camera’s component relative to its root is 0, 0, 170, your item will spawn at those coordinates in world space, which is near the center of the level.

Try replacing that with GetComponentLocation()

Oooops ^.^ well thanks for clearing that up. Do you also have any tips on how to attach the actor to the camera?

Sure. The way I do it is the following:

Item->AttachRootComponentTo(Mesh1P, AttachPoint, EAttachLocation::KeepWorldPosition);

Instead of Mesh1P use your camera component. AttachPoint in my case is the socket I’m connecting to so in your case it should be NAME_none

So in my case “Mesh1P” would be FirsterPersonCameraComponent, right?