1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

UE2 - UT2kX Switch player skin in UE2

Discussion in 'Programming' started by Shadow_knight, Feb 2, 2010.

  1. Shadow_knight

    Shadow_knight Carpe diem!

    Joined:
    Jan 29, 2008
    Messages:
    51
    Likes Received:
    0
    Hi!

    I am playing with UnrealRuntime 2 - what I want to do now is to switch player skin dynamicly (to simulate smiling or angry face by changing the texture), but it seems impossible to change the texture... I am quite suprised the code below doesn't work.
    The pawn inits with default texture - no problem there, when I call both ServerChangeTexture() and ChangeTexture() the texture actually changes but to blank texture. I am doing this in network game.

    Even when I use DynamicLoadObject instead of helper variable MyHappyTex in PostNetReceive() I get the blank texture result. Am I missing something ? Or do these things work differently in Unreal Runtime 2?

    Code:
    class GBPawn extends Pawn;
    
    #exec OBJ LOAD FILE=_PGTX-EmoBoy.utx
    
    var texture MyTexture[2];
    
    var texture MyHappyTex[2];
    
    replication
    {
    	reliable if(Role == Role_Authority)
    		MyTexture, MyHappyTex;  
    }
    
    simulated event PostBeginPlay()
    {
    	Super.PostBeginPlay();
    
    	// if this pawn is supposed to cast dynamic shadows
    	if(bActorShadows && bPlayerShadows)
    	{
    		// Spawn the shadow and intialize it
    		Shadow = Spawn(class'ShadowProjector',None,'',Location);
    		Shadow.ShadowActor = self;
    		Shadow.LightDirection = Normal(vect(1,1,3));
    		Shadow.LightDistance = 380;
    		Shadow.MaxTraceDistance = 3000;
    		Shadow.bBlobShadow = bBlobShadow;
    		Shadow.InitShadow();
    		Shadow.UpdateShadow();
    	}
    
    	MyHappyTex[0]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_clothes_01", class'Texture'));
    	MyHappyTex[1]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_skin", class'Texture'));
    }
    
    function ServerChangeTexture() {
    	MyTexture[0]=MyHappyTex[0];
    	MyTexture[1]=MyHappyTex[1];
    
    	//MyTexture[0]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_clothes_01", class'Texture'));
    	//MyTexture[1]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_skin", class'Texture'));
    }
    
    simulated function changeTexture() {
    	MyTexture[0]=MyHappyTex[0];
    	MyTexture[1]=MyHappyTex[1];
    
    	//MyTexture[0]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_clothes_01", class'Texture'));
    	//MyTexture[1]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_skin", class'Texture'));
    }
    
    
    simulated function PostNetReceive() {
    	//if (MyTexture[0] != none && Skins[0].Name != MyTexture[0].Name)
    	//if (MyTexture[1] != none && Skins[1].Name != MyTexture[1].Name)
    
    	Skins[0]=MyTexture[0];
    	Skins[1]=MyTexture[1];
    }
    
    defaultproperties
    {
    	MyTexture(0)=Texture'CivilTex.cloth'
    	MyTexture(1)=Texture'CivilTex.Skin'
    	MyHappyTex(0)=Texture'_PGTX-Emoboy.emoboy_clothes_01'
    	MyHappyTex(1)=Texture'_PGTX-Emoboy.emoboy_skin'
    	bActorShadows=true
    	bPlayerShadows=true
    	bNetNotify=true
    }
    
     
  2. Shadow_knight

    Shadow_knight Carpe diem!

    Joined:
    Jan 29, 2008
    Messages:
    51
    Likes Received:
    0
    After some digging and trying I have a solution! :)

    It seems there is some problem with replication with more complex objects - textures etc. The code I posted did not work, however, if I replicate an int value and I change the texture according to this value everything works fine. Working code below. Just call changeTexture function with appropriate argument and everything will work. :)

    Code:
    class PogamutMale extends GBPawn
    	config(GBEmohawk);
    
    var Texture	MyTextureOne;
    var Texture	MyTextureTwo;
    var Texture	MyHappyTexOne;
    var texture	        MyHappyTexTwo;
    
    var int repInt;
    
    replication
    {
    	reliable if(Role == Role_Authority)
    		repInt, MyTextureOne, MyTextureTwo, MyHappyTexOne, MyHappyTexTwo;
    }
    
    
    simulated event PostBeginPlay()
    {
    	Super.PostBeginPlay();
    
    	LinkMesh(Mesh(DynamicLoadObject("_PGA-EmoboySized.emoboy_mesh", class'Mesh')),false);
    
    	Skins[0]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_skin", class'Texture'));
    	Skins[1]=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_clothes_01", class'Texture'));
    
    	MyHappyTexOne=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_skin", class'Texture'));
    
    	MyHappyTexTwo=Texture(DynamicLoadObject("_PGTX-Emoboy.emoboy_clothes_01", class'Texture'));
    
    	MyTextureOne=Texture(DynamicLoadObject("CivilTex.cloth", class'Texture'));
    	MyTextureTwo=Texture(DynamicLoadObject("CivilTex.Skin", class'Texture'));
    }
    
    simulated function ChangeTexture(int i) {
         repInt = i;
    }
    
    simulated event PostNetReceive() {
    	if (repInt == 1) {
    		Skins[0] = MyTextureOne;
    		Skins[1] = MyTextureTwo;
    		repInt = 0;
    	} else if (repInt == 2) {
    		Skins[0]=MyTexture[0];
    		Skins[1]=MyTexture[1];
                    repInt = 0;
    
           }
    }
    
    defaultproperties
    {
    	MyTextureOne=Texture'CivilTex.cloth'
    	MyTextureTwo=Texture'CivilTex.Skin'
    	MyHappyTexOne=Texture'_PGTX-Emoboy.emoboy_skin'
    	MyHappyTexTwo=Texture'_PGTX-Emoboy.emoboy_clothes_01'
    	Mesh=SkeletalMesh'_PGA-EmoboySized.emoboy_mesh'
    	IdleAnim="stand_normal"
    	MovementAnims[0]="run_normal"
    	MovementAnims[1]="run_normal"
    	MovementAnims[2]="run_normal"
    	MovementAnims[3]="run_normal"
    	TurnLeftAnim="walk_loop"
    	TurnRightAnim="walk_loop"
    	bPhysicsAnimUpdate=true
    	bCanCrouch=false
    	GroundSpeed=440
    	Skins(0)=Texture'_PGTX-Emoboy.emoboy_skin'
    	Skins(1)=Texture'_PGTX-Emoboy.emoboy_clothes_01'
    	bActorShadows=true
    	BaseEyeHeight=128
    	bNetNotify=true
    }
    
    
    best,
    sk
     

Share This Page