Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

Tutorial: Creating custom AnimNodes

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tutorial: Creating custom AnimNodes

    I originally wrote this for UT3, but it should be pretty much the same for UDK. It is intended for coders already familiar with UnrealScript.

    As you may be aware, in UDK player animations are generally driven an AnimTree. This is created in the editor, and is composed of AnimNodes that select what animations are played based on the state of the player. It is possible to extend this system by creating custom AnimNodes using UnrealScript. In this example an AnimNode is created for switching animation paths based on the weapon the pawn is holding.

    Firstly, the node itself:

    Code:
    class MyAnimBlendByWeaponType extends UTAnimBlendBase;
    
    enum MyWeaponType 
    {
    	MWT_Sword,
            MWT_Gun,
            MWT_Bow
    };
    
    simulated function SetWeaponAnimType(MyWeaponType weapAnimType) 
    {
    	SetActiveChild(weapAnimType, BlendTime);
    }
    
    DefaultProperties
    {
    	Children(0)=(Name="Sword")
    	Children(1)=(Name="Gun")
    	Children(2)=(Name="Bow")
    	bFixNumChildren=True
    }
    So this node is a subclass of UTAnimBlendBase. This is a generic node which can have a number of child branches, and the active branch can be set via a function call. This subclass set the name for the child branches and prevents them being edited in the editor.

    At this point you can already add the node to an AnimTree. But it will not do anything, as there is no code to alter the active branch.

    Next you need to alter your pawn class to update the nodes.
    Code:
    class MyAnimPawn extends UTPawn;
    
    var array<MyAnimBlendByWeaponType> WeaponTypeAnimNodes;
    
    simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
    {
    	local MyAnimBlendByWeaponType BlendByWeaponType;
    
    	super.PostInitAnimTree(SkelComp);
    	if (SkelComp == Mesh)
    	{
    		foreach mesh.AllAnimNodes(class'MyAnimBlendByWeaponType', BlendByWeaponType) {
    			WeaponTypeAnimNodes[WeaponTypeAnimNodes.Length] = BlendByWeaponType;
    		}
    	}
    }
    
    simulated function SetWeaponAnimType(MyWeaponType weapAnimType) {
    	local int i;
    
    	for (i = 0; i < WeaponTypeAnimNodes.length; i++) {
    		WeaponTypeAnimNodes[i].SetWeaponAnimType(weapAnimType);
    	}
    }
    The PostInitAnimTree function accesses the AnimTree to populate a list of all the MyAnimBlendByWeaponType nodes. This means you can have as many as you want in the tree, the code will be able to find and update all of them when the held weapon changes.

    Specifically for this case, a WeaponAttachment subclass is needed to inform the pawn what type of weapon they are holding:

    Code:
    class MyWeaponAttachment extends UTWeaponAttachment;
    
    var MyWeaponType WeaponAnimType;
    
    simulated function AttachTo(UTPawn OwnerPawn) 
    {
            local MyAnimPawn AnimPawn;
            
            super.AttachTo(OwnerPawn);
    
            AnimPawn= MyAnimPawn(OwnerPawn);
    	if (AnimPawn != none) 
            {
    		AnimPawn.SetWeaponAnimType(WeaponAnimType);
    	}
    }
    
    DefaultProperties
    {
       WeaponAnimType=MWT_Sword
    }
    Each specific weapon attachment subclass then set the WeaponAnimType in its default properties. The WeaponAttachment class is replicated and attachment processed on client machines, so this ensures that the pawn's animations will always match their displayed weapon.

  • #2
    Awesome Immortius, I was always curious how you did that for Nb.

    Comment


    • #3
      Thanks immortius! it was very helpful!! and exactly I wanted!!
      by the way I've got a error from Frontend with "MyAnimPawn class"

      like so - > (MyAnimPawn.uc(18) : Error, Unrecognized type 'MyWeaponAnimType')

      and I really want to make it work.. So please let me know how to fix it out

      Comment


      • #4
        Ah, sorry. There was a typo in the MyAnimPawn code, should have MyWeaponType instead of MyWeaponAnimType.

        Comment


        • #5
          Cheers Man!! thanks million!! : )

          Comment


          • #6
            sorry to bother you Immortius then I've got this one now..
            I've tried something other operation, that I think similar, to fix it out though, I couldn't fix it at all kkk
            so, if you don't mind help me once more please : )

            ---I've got this------------------------------------------------------------
            MyWeaponAttachment.uc(11) : Error, Bad or missing expression in '='
            ---------------------------------------------------------------------------

            Comment


            • #7
              Fantastic immortius! Thank you, this is really helpful!

              Comment


              • #8
                Originally posted by KyuIn View Post
                ---I've got this------------------------------------------------------------
                MyWeaponAttachment.uc(11) : Error, Bad or missing expression in '='
                ---------------------------------------------------------------------------
                You're expecting a lot from me if I'm supposed to guess what you're doing wrong without you showing your code.

                Comment


                • #9
                  Well.. I haven't had Programming discussion
                  I thought, it may make you to read much more kkk
                  And, the last post I made, It was my bad kk I worte your code with a mistake.

                  Anyway I tried to mix my code with your code up and when I changed class name
                  MyAnimPawn to MyPawn in MyWeaponAttachment.uc It makes errors


                  MyPawn
                  class MyPawn extends GamePawn;

                  var array<MyAnimBlendByWeaponType> WeaponTypeAnimNodes;

                  simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
                  {
                  local MyAnimBlendByWeaponType BlendByWeaponType;

                  super.PostInitAnimTree(SkelComp);
                  if (SkelComp == Mesh)
                  {
                  foreach mesh.AllAnimNodes(class'MyAnimBlendByWeaponType', BlendByWeaponType) {
                  WeaponTypeAnimNodes[WeaponTypeAnimNodes.Length] = BlendByWeaponType;
                  }
                  }
                  }

                  simulated function SetWeaponAnimType(MyWeaponType weapAnimType) {
                  local int i;

                  for (i = 0; i < WeaponTypeAnimNodes.length; i++) {
                  WeaponTypeAnimNodes[i].SetWeaponAnimType(weapAnimType);
                  }
                  }


                  simulated event PostBeginPlay()
                  {
                  `log("My pawn is now alive, and well!");
                  }
                  defaultproperties
                  {
                  Begin Object class=SkeletalMeshComponent Name=SkeletalMeshComponent0

                  bHasPhysicsAssetInstance=True
                  bEnableSoftBodySimulation=True
                  bSoftBodyAwakeOnStartup=True


                  SkeletalMesh=SkeletalMesh'SimDate.Mesh.Imp02'
                  AnimSets[0]=AnimSet'SimDate.AnimSet.Imp01AnimSet'
                  AnimTreeTemplate=AnimTree'SimDate.AnimSet.Imp01Ani mTree'
                  PhysicsAsset=PhysicsAsset'SimDate.Physics.Imp01_Ph ysics'

                  End Object



                  Mesh=SkeletalMeshComponent0
                  Components.Add(SkeletalMeshComponent0)
                  }

                  MyWeaponAttachment
                  class MyWeaponAttachment extends UTWeaponAttachment;

                  var MyWeaponType WeaponAnimType;

                  simulated function AttachTo(UTPawn OwnerPawn)
                  {
                  local MyPawn AnimPawn;

                  super.AttachTo(OwnerPawn);

                  AnimPawn= MyPawn(OwnerPawn);
                  if (AnimPawn != none)
                  {
                  AnimPawn.SetWeaponAnimType(WeaponAnimType);
                  }
                  }

                  DefaultProperties
                  {
                  WeaponAnimType=MWT_Sword
                  }
                  god It's very confuse kkk thanks.

                  Comment


                  • #10
                    Your WeaponAttachment class subclasses UTWeaponAttachment, which expects the pawn it is attached to to be a UTPawn. Your pawn class subclasses GamePawn, so is not a UTPawn. So the weapon attachments won't work with your pawn.

                    Comment


                    • #11
                      Ah!!!!! So that why it was not working!! Thanks a lot!! now I can see it : )

                      Comment


                      • #12
                        immortius can u help; I want to have multiple Animation sets how do i set weapons to use specific animsets?

                        Comment


                        • #13
                          THis is beautiful! This $#!+ works!!!

                          Comment


                          • #14
                            For some reason, My Idle animation for one of my weapons is not working...The character plays the rifle animation instead:

                            See pic:


                            Uploaded with ImageShack.us

                            THe one on the left is the Idle and the right is when the character is moving

                            Ideas anyone?

                            Comment


                            • #15
                              bUMP! And the jump animation doesnt work...the char plays the run anim when falling.

                              Comment

                              Working...
                              X