Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#Actualratrace135

Posted 12 March 2013 - 07:17 PM

- Must my model be in a specific directory? If so, which one?

Nope, you can put it anywhere you want (though the package itself should be somewhere in the Content folder). And don't worry about the file type and path... unless you're like me and you enjoy typing all of it out tongue.png

StaticMesh=TexPropCube_Dup would get you the same result as StaticMesh=StaticMesh'UN_SimpleMeshes.TexPropCube_Dup'.

 

 

- Do I need to use unrealscript to do it, or is that simply the recommended way?

If you only want the mesh attached to the player for one part of the level or for some other scripted event, it might be better to use the AttachToActor node in Kismet. If you want the mesh attached all the time though, it'd probably be better to have it in Unrealscript. Also, you can only attach to an actor in Kismet, but in Unrealscript, you can attach components to an actor or to the actor's SkeletalMeshComponents.

 

If you're attaching something to the player, then you'll be attaching directly to the actor (as opposed to if you were attaching something to an enemy pawn, where you'd be attaching to the actor's body mesh). One way is with the DefaultProperties like you have written out. Another way is to create and attach the components dynamically, which would look something like this:

var() SkeletalMeshComp Comp;    //Can also be a StaticMeshComponent.... or any other component type

function AttachMesh()
{
   Comp = new(self) class'SkeletalMeshComponent';
   Comp.SetSkeletalMesh( WhateverMesh );
   Comp.SetLightEnvironment( MyLightEnvironment ); 

   AttachComponent( Comp );
}

You can use a local variable instead for the component you're attaching, but if you later want to detach it from the actor, play an animation, etc, it'll be easier if you kept the variable. Now to animations... Unless you're using an AnimTree, you're going to have to call the animations using the SkeletalMeshComponent's PlayAnim(name AnimName, optional float Duration, optional bool bLoop) function (I left out the rest of the optional variables but those are the main ones you'll be using). It's not difficult, but you'll want to avoid playing an animation while an existing one is being played on the component, as the first animation will be stopped and can be pretty ugly unless the first animation is something subtle like a weapon's idle animation. Also, you're going to need to have an AnimNodeSequence to play the animations on (see code below).

 

Since static meshes can't play anims, I'm going to pretend that the TexPropCube_Dup is a skeletal mesh for an example.

class BreakDancingCube extends Actor
   placeable;

var() SkeletalMeshComponent CubeMesh;
var name CubeMeshAnim;

simulated function PostBeginPlay()
{
   super.PostBeginPlay();

   CubeMesh.PlayAnim( CubeMeshAnim,, True );   //Play a looping animation
}

DefaultProperties
{
Begin Object Class=AnimNodeSequence Name=MeshSequenceA    //Don't need to change any settings, but you need to create it
End Object

Begin Object Class=SkeletalMeshComponent Name=BasicMesh
        SkeletalMesh=SkeletalMesh'UN_SimpleMeshes.TexPropCube_Dup'
        AnimSets(0)=AnimSet'UN_SimpleMeshes.TexPropCube_Anims'        //Totally made-up anim set
        Animations=MeshSequenceA                                      //Animations won't play without this line
        Materials(0)=Material'EditorMaterials.WidgetMaterial_X'
        LightEnvironment=MyLightEnvironment
        Scale3D=(X=0.25,Y=0.25,Z=0.5)
End Object
CubeMesh=BasicMesh       //So that we can reference this in the code
Components.Add(BasicMesh)

CubeMeshAnim=BreakDance   //Made up anim name for the made up anim set
}

#1ratrace135

Posted 12 March 2013 - 07:15 PM

- Must my model be in a specific directory? If so, which one?

Nope, you can put it anywhere you want (though the package itself should be somewhere in the Content folder). And don't worry about the file type and path... unless you're like me and you enjoy typing all of it out :P

StaticMesh=TexPropCube_Dup would get you the same result as StaticMesh=StaticMesh'UN_SimpleMeshes.TexPropCube_Dup'.

 

- Do I need to use unrealscript to do it, or is that simply the recommended way?

If you only want the mesh attached to the player for one part of the level or for some other scripted event, it might be better to use the AttachToActor node in Kismet. If you want the mesh attached all the time though, it'd probably be better to have it in Unrealscript. Also, you can only attach to an actor in Kismet, but in Unrealscript, you can attach components to an actor or to the actor's SkeletalMeshComponents.

 

If you're attaching something to the player, then you'll be attaching directly to the actor (as opposed to if you were attaching something to an enemy pawn, where you'd be attaching to the actor's body mesh). One way is with the DefaultProperties like you have written out. Another way is to create and attach the components dynamically, which would look something like this:

var() SkeletalMeshComp Comp;    //Can also be a StaticMeshComponent.... or any other component type

function AttachMesh()
{
   Comp = new(self) class'SkeletalMeshComponent';
   Comp.SetSkeletalMesh( WhateverMesh );
   Comp.SetLightEnvironment( MyLightEnvironment ); 

   AttachComponent( Comp );
}

You can use a local variable instead for the component you're attaching, but if you later want to detach it from the actor, play an animation, etc, it'll be easier if you kept the variable. Now to animations... Unless you're using an AnimTree, you're going to have to call the animations using the SkeletalMeshComponent's PlayAnim(name AnimName, optional float Duration, optional bool bLoop) function (I left out the rest of the optional variables but those are the main ones you'll be using). It's not difficult, but you'll want to avoid playing an animation while an existing one is being played on the component, as the first animation will be stopped and can be pretty ugly unless the first animation is something subtle like a weapon's idle animation. Also, you're going to need to have an AnimNodeSequence to play the animations on (see code below).

 

Since static meshes can't play anims, I'm going to pretend that the TexPropCube_Dup is a skeletal mesh for an example.

class BreakDancingCube extends Actor
   placeable;

var() SkeletalMeshComponent CubeMesh;
var name CubeMeshAnim;

simulated function PostBeginPlay()
{
   super.PostBeginPlay();

   CubeMesh.PlayAnim( CubeMeshAnim,, True );   //Play a looping animation
}

DefaultProperties
{
Begin Object Class=AnimNodeSequence Name=MeshSequenceA    //Don't need to change any settings, but you need to create it
End Object

Begin Object Class=SkeletalMeshComponent Name=BasicMesh
        SkeletalMesh=SkeletalMesh'UN_SimpleMeshes.TexPropCube_Dup'
        AnimSets(0)=AnimSet'UN_SimpleMeshes.TexPropCube_Anims'        //Totally made-up anim set
        Animations=MeshSequenceA                                      //Animations won't play without this line
        Materials(0)=Material'EditorMaterials.WidgetMaterial_X'
        LightEnvironment=MyLightEnvironment
        Scale3D=(X=0.25,Y=0.25,Z=0.5)
End Object
Cube Mesh=BasicMesh       //So that we can reference this in the code
Components.Add(BasicMesh)

CubeMeshAnim=BreakDance   //Made up anim name for the made up anim set
}

PARTNERS