Results 1 to 5 of 5
  1. #1
    MSgt. Shooter Person
    Join Date
    Dec 2010
    Posts
    291

    Default my Question about modifing Pawn Components...

    Hi;

    I add a Component to my pawn. The question is how could I modify dynamically it's Location in UScript in run-time...?

    (... I dont want to do this, using "Translation = (X=0.0,Y=0.0,Z=0.0)" in "defaultproperties" ).


    Here is my Pawn defaultproperties codes:

    Code:
    defaultproperties
    {
    
    Begin Object class=SkeletalMeshComponent name=MyPawn
            ...
    End Object
    	Mesh = MyPawn
    	Components.Add(MyPawn)
    
          ...
    
    
    Begin Object class=StaticMeshComponent name=theMesh
    	StaticMesh = StaticMesh 'MSDG_Package.Models.myBox';
    End Object
    	Components.Add(theMesh)
           ...
    }

    Thanks.

  2. #2
    MSgt. Shooter Person
    Join Date
    Jun 2009
    Posts
    399

    Default

    Assig the component in your DefaultProperties to a variable. Then...
    {ReferenceObject}.SetTranslation(NewTranslation)

    In your example: Mesh.SetTranslation(NewTranslation).

  3. #3
    MSgt. Shooter Person
    Join Date
    Dec 2010
    Posts
    291

    Default

    RattleSN4K3:
    Thanks for reply:
    In DefaultProperties of my Pawn, the Mesh.SetTranslation(NewTranslation) modifies the main mesh of my Pawn, but I want to change the mesh of the component (I mean the second mesh, the attached component )
    I don't know how make a reference to this second mesh ( StaticMesh = StaticMesh 'MSDG_Package.Models.myBox'; ), in UnrealScript.

  4. #4
    MSgt. Shooter Person
    Join Date
    Jun 2009
    Posts
    399

    Default

    By assigning something in the manner of MyMesh=OldMesh, you don't create a clone of a mesh. It's just a reference/pointer to the original object.
    Destroying OldMesh will set MyMesh to none when OldMesh gets garbage collected.
    If you set something on MyMesh, OldMesh has the same value.
    ==> It's still the same Object.

    So you can assign any, in the defaultproperties, created objects to a variable and use it in the code.

    Code:
    class MyActor1 extends Actor;
    
    // used for reference to the component
    var StaticMeshComponent MyComp1;
    
    event PostBeginPlay()
    {
    	super.PostBeginPlay();
    
    	MyComp1.SetTranslation(vect(10,10,10));
    }
    
    defaultproperties
    {
    	Begin Object class=StaticMeshComponent name=StaticMeshComponent1
    		StaticMesh=StaticMesh 'MSDG_Package.Models.myBox'
    	End Object
    	Components.Add(StaticMeshComponent1)
    
    	// Set the var
    	MyComp1=StaticMeshComponent1
    }
    Another approach
    Code:
    class MyActor1 extends Actor;
    
    event PostBeginPlay()
    {
    	local StaticMeshComponent TempComp;
    
    	super.PostBeginPlay();
    
    	foreach ComponentList(class'StaticMeshComponent', TempComp) {
    		// @TODO check if name is automacally set to NAME_X format
    		// temporally compare the prefix name
    		if (Left(TempComp.Name, 6) ~= "MyMesh") {
    			TempComp.SetTranslation(vect(10,10,10));
    		}
    	}
    }
    
    defaultproperties
    {
    	Begin Object class=StaticMeshComponent name=StaticMeshComponent1
    		StaticMesh=StaticMesh 'MSDG_Package.Models.myBox'
    	End Object
    	Components.Add(StaticMeshComponent1)
    }
    Complete dynamically:
    Code:
    class MyActor extends Actor;
    
    var StaticMeshComponent MyComp;
    
    event PostBeginPlay()
    {
    	local StaticMesh sm;
    	
    	super.PostBeginPlay();
    	
    	MyComp = new(self,"MyMesh") class'StaticMeshComponent';
    	sm = StaticMesh(DynamicLoadObject("MSDG_Package.Models.myBox", class'StaticMesh'));
    	MyComp.SetStaticMesh(sm);
    	MyComp.SetTranslation(vect(10,10,10));
    
    	AttachComponent(MyComp);
    }
    
    defaultproperties
    {
    }
    Hope, it helps.

  5. #5
    MSgt. Shooter Person
    Join Date
    Dec 2010
    Posts
    291

    Default

    RattleSN4K3:
    Thanks, you're awesome..., it works.


 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright ©2009-2011 Epic Games, Inc. All Rights Reserved.
Digital Point modules: Sphinx-based search vBulletin skin by CompletevB.com.