I have a similar problem, but instead of attach the spawned skeletal mesh to Player's pawn, I want to attach it to another skeletal mesh that is already attached to Pawn. That's like attach a skeletal mesh to player's weapon.
In other words what I want to do is:
Begin game & spawn player's pawn -> spawn weapon1 -> attach weapon1 to pawn's socket -> spawn weapon2 -> attach weapon2 to weapon1 socket
So far, I was able to spawn and attach successfully only Weapon1, while I've lot of problems with Weapon2.
That's what I tried:
In MyPawn.uc
Code:
function AddDefaultInventory()
{
Weapon1=Spawn(class'MYWeapon1,self);
Weapon1.AttachWeaponTo(Mesh, Weapon_socket1);
Weapon1.AddSecondWeapon();
}
In Weapon1.uc
Code:
class MYWeapon1 extends MYWeapon1Group;
var MYWeapon2 Weapon2;
var name Weapon_socket2;
function AddSecondWeapon()
{
Weapon2=Spawn(class'MYWeapon2',self);
//Weapon2.AttachWeaponTo(Mesh, Weapon_socket2);
/*When I try to use AttachWeaponTo function it returns me a type mismatching error in parameter 1 (I don't get why though), so I went to an AttachComponentToSocket instead*/
Weapon2.AttachComponentToSocket(Mesh, Weapon_socket2);
}
In MYWeapon2Group.uc
Code:
class MYWeapon2Group extends UDKWeapon;
var name Weapon2AttachmentSocketName;
function AttachComponentToSocket(ActorComponent Component, name SocketName)
{
local MYWeapon1 V;
V = MYWeapon1(Instigator.Weapon);
/*Here is where the problem is...
whatever of the following lines I use, it returns the error "Unrecognized AttachComponentToSocket in class MYWeapon2"*/
//V.Mesh.AttachComponentToSocket(Mesh,Weapon2AttachmentSocketName);
Component.AttachComponentToSocket(Mesh,Weapon2AttachmentSocketName);
}
DefaultProperties
{
Begin Object Class=SkeletalMeshComponent Name=SkeletalMeshComponent1
CollideActors=false
AlwaysLoadOnClient=true
AlwaysLoadOnServer=true
bUseAsOccluder=FALSE
bUpdateSkelWhenNotRendered=false
bIgnoreControllersWhenNotRendered=true
bOverrideAttachmentOwnerVisibility=true
bAcceptsDynamicDecals=FALSE
End Object
Components.Add(SkeletalMeshComponent1)
Mesh=SkeletalMeshComponent1
Weapon2AttachmentSocketName=Weapon_socket2
}
I could easily solve this problem attaching Weapon2 directly to player's pawn, but that's not what I want.
Any idea?
Bookmarks