Download

Help Animating Weapon Attachment

Hello guys.

I am trying to play some animations on my custom weapons, however as I am using BehindView Camera with some offsets (3rd person), so the weapon model which is being hold by my pawn is controlled by UTWeaponAttachment Class.

After reading through the UTWeaponAttachment code, there is a function to play animations:


simulated function ThirdPersonFireEffects(vector HitLocation)
{
    local UTPawn P;
    if ( EffectIsRelevant(Location,false,MaxFireEffectDistance) )
    {
        // Light it up
        CauseMuzzleFlash();
    }

    // Have pawn play firing anim
    P = UTPawn(Instigator);
    if (P != None && P.GunRecoilNode != None)
    {
        // Use recoil node to move arms when we fire
        P.GunRecoilNode.bPlayRecoil = true;
    }

    if (Instigator.FiringMode == 1 && AltFireAnim != 'None')
    {
        Mesh.PlayAnim(AltFireAnim,,, false);
    }
    else if (FireAnim != 'None')
    {
        Mesh.PlayAnim(FireAnim,,, false);
    }
}

So I am having some hard time to call these animations using my weapon class. In example, I created a custom reload system for my weapons, extending the UTWeapon Class. And whenever the player presses the “R” key it plays the animation on the pawn owner of the weapon:


//reload function to play reload animation///////////////////////
exec function Reload() {

  //this statement will prevent weapon reloading when ammo is full
  if (AmmoTotal > 0 && !bIsReloading && AmmoCount < MaxAmmoCount) {
    ForceEndFire();
    bIsReloading = true;     
    //PlayWeaponAnimation('WeaponReload', 1.9);

        //this will play the custom reload animation only on the half top body
        UTPawn(Owner).TopHalfAnimSlot.SetActorAnimEndNotification(true);

                                                  //AnimName, Rate, BlendInTime, BlendOutTime     
        UTPawn(Owner).TopHalfAnimSlot.PlayCustomAnim('reload_rocket_UT3', 1, 0.25, 0.25);            

    WeaponPlaySound(WeaponEquipSnd);

    //this timer will be triggered after the duration of the reload animation which is 3.13 seconds
    setTimer(3.13, false, 'AddAmmoToMag');
  }

}
//reload function to play reload animation///////////////////////

Untill here its fine, the weapon code plays a reload animaton on the pawn (player model), however I need to play aswell the animation on the UTWeaponAttachment of this gun, like the magazine being ejected and inserted a new one. I already have the two animations synchronized, the pawn reload and weapon reload, I just don’t know how to call this animation from the weapon code to be played on the weapon attachment class.

Here is my Attachment Class:


class UTAttachment_AIRPG7 extends UTWeaponAttachment;

DefaultProperties
{    

    Begin Object class=UTAnimNodeSequence Name=MeshSequenceA
    End Object

    Begin Object Name=SkeletalMeshComponent0
        SkeletalMesh=SkeletalMesh'rpg7.rpg7'
        Scale=0.9000000
        Animations=MeshSequenceA
        AnimSets(0)=AnimSet'rpg7.animations'
    End Object    
    Mesh=SkeletalMeshComponent0

    //play pistol holding animations//
    WeapAnimType=EWAT_ShoulderRocket

    bMakeSplash=True

    //muzzleflash for 3rd person model
    MuzzleFlashSocket=MuzzleFlashSocket
    MuzzleFlashPSCTemplate=ParticleSystem'WP_RocketLauncher.Effects.P_WP_RockerLauncher_Muzzle_Flash'

    //<DO NOT MODIFY>
    WeaponClass=Class'UTWeap_AIRPG7'
}

Now i tried to access this attachment class by my weapon code, first by declaring a variable that will hold this attachment class:


class UTWeap_AIRPG7 extends WeaponReloadRocket;

//An instance of the RPG7 Attachment class so we can animate the attachment (3rd person weapon) in game
var UTAttachment_AIRPG7 RPG7Attachment;
RPG7Attachment=Class'UTAttachment_AIRPG7'

Then on the fire event of this weapon UTWeap_AIRPG7 (because I need that the rocket actually disappears whenever the rpg fires), I tried to call the custom fire animation for the weapon attachment:


//function to fire gun and play animation/////////////////////////
simulated function FireAmmunition()
{
        //this will play the allah_akbar sound
        PlaySound(SoundCue'dhikr.allah_akbar_1_Cue', false, true, true, vect(0,0,0), false); 

        RPG7Attachments.Mesh.PlayAnim('rocket_shoot',,, false);

        super.FireAmmunition();
}
//function to fire gun and play animation/////////////////////////

However whenever I compile, it gives me the error message “Unexpected RPG7Attachments”.

Any help?

Hello guys. I had an idea, and what if I could create a kind of global variable, like IsWeaponReloading that can be accessed by both UTWeapon and UTWeaponAttachment. My reload code runs inside UTWeapon, so whenever the reload sequence begins it will set the IsWeaponReloading = true, so on the UTWeaponAttachment i will do a function that checks if IsWeaponReloading = true then play the mesh.Playanim.

How can I do this?

I don’t know. My game characters are all sprites and I’ve never tried doing this before. I would recommend taking a look for where FireAnim and AltFireAnim are defined. Set up a ReloadAnim the same way

Does your weapon have a anim tree instanced? should work

Hello guys. Thanks for taking your time and trying to help me. I already found a solution, after reading line by line of the UTWeapon.uc, UTPawn.uc and UTWeaponAttachment.uc

I learned that the play anim function on UTWeaponAttachment can be only called by UTPawn.uc, so I created this simulated function on UTPawn.uc:


simulated function RPG7ReloadAnim()
{
  if(CurrentWeaponAttachment != None)
     //PlayAnim(bool bLoop, float InRate, float StartTime)
     CurrentWeaponAttachment.Mesh.PlayAnim('rpg7_anim_reload',,, false);
}

Then on my weapon class, inside my reload code, I simply called this function on my Pawn:


UTPawn(Owner).RPG7ReloadAnim();


Then it worked!!!

I just need to adjust the reload animation on my weapon to synchronize perfectly with the pawn reload animation.

Now I understood that the UTWeaponAttachment class is a skeletal mesh, and it can have everything skeletal mesh has (animation set, animation tree and so on).

Thanks for the help, and soon I will update a new video of my rpg7 reload animation.

Cheers.

:smiley: