UE3 - UDK Changing the Texture of StaticMesh

  • 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.

Shadow_knight

Carpe diem!
Jan 29, 2008
51
0
6
Prague
Hi!

Recently I switched from UT2004 to UDK. Currently, I am struggling with static meshes. In UT2004 it was no problem to change the texture of StaticMesh. In UDK there is this new material system and I am a little bit confused. I have this code (that works):

Code:
class PathMarker extends StaticMeshActor
	placeable;

var MaterialExpressionTextureSample myMaterial;

DefaultProperties
{
	//Good old UT2004 way: :/
	//DrawType=DT_StaticMesh
	//StaticMesh=StaticMesh'UN_SimpleMeshes.TexPropCube_Dup'
	//Skins(0)=Texture'EngineResources.WhiteSquareTexture'

	Begin Object Class=StaticMeshComponent Name=PathMarkerComponent
		bUsePrecomputedShadows=true
		bAcceptsStaticDecals=false
		bAcceptsDynamicDecals=false
		StaticMesh=StaticMesh'UN_SimpleMeshes.TexPropCube_Dup'
		WireframeColor=(R=255,G=0,B=0,A=255) 
		bDisableAllRigidBody=true
		CastShadow=false
		RBChannel=RBCC_Nothing
		bCastDynamicShadow=false
		bSelfShadowOnly=true
		bAcceptsLights=true
		bAcceptsDynamicLights=false
		bAcceptsDynamicDominantLightShadows=true
	End Object
	StaticMeshComponent=PathMarkerComponent
	Components.Remove(StaticMeshComponent0)
	Components.Add(PathMarkerComponent)

	CollisionComponent=None
	bCollideActors=false
	bCollideWorld=false
	
	DrawScale=0.03
	bStatic=false
}

Now I would like to change the Texture of StaticMesh'UN_SimpleMeshes.TexPropCube_Dup' to something else (and I would like to leave the original mesh file intact). Either in DefaultProperties or dynamically in the code. Is there somewhere a tutorial or an example how to do it? So far I've found nothing.

Thanks,
sk
 

Shadow_knight

Carpe diem!
Jan 29, 2008
51
0
6
Prague
I need to change it in .uc class that represents the mesh, because I will spawn the mesh dynamically at runtime (imagine each character in the game will have a cube spawned above his head, that will change shape and color).

sk
 

inferyes

Spaced In
Aug 16, 2009
504
0
0
Not 100% sure if this is right, but you could just make a function and call it.

function changetexture()
{
StaticMesh=StaticMesh'newtexturelols';
loginternal("texture changed");
}
 

Shadow_knight

Carpe diem!
Jan 29, 2008
51
0
6
Prague
Ok.. Some updates. I wasn't able to solve the problem and by looking on a code of few UDK projects - my desired approach was never used in them.

On UDN I've found somewhat related topics to this:

http://udn.epicgames.com/Three/InstancedMaterials.html

and

http://udn.epicgames.com/Three/ScriptedTextures.html

Since I wasn't able to solve it (although it may be possible through material changing I suspect), I used different way for my visualization. I simply used the emitter - it gets replicated easily + you can customize it pretty well. If someone would be interested in the code, I can post it here.

Best,
sk
 

Shadow_knight

Carpe diem!
Jan 29, 2008
51
0
6
Prague
Heh. I gave up, start looking to another things and BAM - there it was... DynamicSMActor is the class I was looking for - you can set up a static mesh with this class. Now to change its texture, you need to change ReplicatedMaterial variable to your MaterialInstanceConstant with your desired texture set. That is all. I wonder - really no-one on this forum knew about DynamicSMActor class? :) (the naming is a little bit confusing, because you won't find it when searching "Mesh" in UDK src...)

sk