Attach Actor to socket via C++

Not sure what the “LASERTAG_API” thing is for either, it starts to show up now when you make a class through the editor, its new to 4.3.

I think I’m getting closer to getting this put together. I didn’t spawn the weapon, that’s what I’m working on now, just trying to figure out SpawnActor, apparently I need a class of the weapon to pass into SpawnActor? All I have is a mesh, so Im assuming they mean blueprint of that mesh, and then I can pass that blueprint into SpawnActor as a class?

I have another question for you; in your AttachWeaponToPawn method, were is the weapon? I’m looking at the AttachRootComponentTo call and I don’t see an item being attached.

With this code:



 void ALaserTagCharacter::BeginPlay()
 {
     FActorSpawnParameters spawnParams;
     spawnParams.Owner = this;
 
     AMyWeapon* wep = GetWorld()->SpawnActor<AMyWeapon>(AMyWeapon::StaticClass(), spawnParams);
     if (wep)
     {
         wep->AttachWeaponToPawn(GetWorld()->GetFirstPlayerController()->GetPawn(), TEXT("HeroTPP"));
     }
 }
 

I’m able to see the MyWeapon class show up in the scene outliner when I run the game, but there is no weapon mesh. I think I may be using the AttachWeaponToPawn method incorrectly, or I misunderstood its intended purpose.

Spawn the item with owner set to NULL.
bCollisionFail = false;
Instegator = NULL;

The owner is set when you actualy are holding it, or else its NULL.
I can`t say i know all the parameters for FActorSpawnParameters and its uses, so for me it was a bit of trail and error as far as i can see now.
Everything is ok, let me know am sure we get it to work.

Am using it so :slight_smile:

Ok Im trying to trouble shoot segments of this code, I found that Im not getting the correct name from my mesh. In the code im checking for the name of a USkeletalMeshComponent:



 if (playerMesh->GetName() == ComponentName)


The GetName() should be returning “HeroTPP”, but instead it is returning “CharacterMesh0”. So I change the code to check for “CharacterMesh0” and then the MyWeapon class sucessfully attached to the Character.

The weapon mesh spawns pointing straight down, relative to the character, Im not sure how to get it pointed in the correct direction.
EDIT I was able to do a local rotate in the editor of the weapon socket, now its pointing in the correct direction.

How can I check for the real name instead, which is “HeroTPP”? I tried to use GetReadableName() name and that gave me something closer; it returned “MyCharacter_C_12.CharacterMesh0 HeroTPP”.