From Unreal Wiki, The Unreal Engine Documentation Site
Jump to navigation Jump to search
UT2003 :: Object >> Material >> RenderedMaterial >> BitmapMaterial >> ScriptedTexture (Package: Engine)

A ScriptedTexture is a dynamic texture that can be drawn on in real-time with UnrealScript, used (for instance) for the monitors in DM-Insidious.

NOTE: ScriptedTextures do not work in the software or OpenGL renderers. If you use ScriptedTextures people on Mac or Linux and people using the software renderer will just see white. Epic has stated that this issue will not be resolved.

Solid Snake: I think this is now no longer true. I recall reading somewhere that scripted textures now work in OpenGL. Not sure about either Linux/Mac, but I assume since the Linux version of UT2004 is primarily OpenGL (I think...) it should also work there. Here is a indirect reference, http://www.unrealadmin.org/forums/printthread.php?threadid=12874. It states that OpenGL no longer renders ScriptedTextures upside down...

Bob_The_Beheader: I use OpenGL in the Windows version, and the scripted textures do not appear. It's slightly annoying. I like seeing my nick on the hellbender licence plate.

See ScriptedTexture (UT) for the UT version of this class.


Actor Client 
The actor which is responsible for drawing the dynamic content on this ScriptedTexture.
Each frame when Revision > OldRevision, this actor's RenderTexture event is called. CameraTextureClients point their assigned ScriptedTexture's Client property to themselves on game start.
int OldRevision (transient, const) 
The last drawn revision.
int RenderTarget (transient, const) 
Viewport RenderViewport (transient, const) 
int Revision (transient) 
Current revision. Increment this property to redraw the ScriptedTexture the next frame it is used.


All these methods are native and final.

DrawPortal (int X, int Y, int Width, int Height, Actor CamActor, vector CamLocation, rotator CamRotation, optional int FOV, optional bool ClearZ) 
In the rectangle set by X, Y, Width, and Height, draws what the viewport would render from a camera at CamActor's position, offset by CamLocation, rotated by CamRotation. Absolutely impossible to do in UT, this is the Right Way to set up for a bank of CCTV monitors if you don't use CameraTextureClients.
DrawText (int StartX, int StartY, coerce string Text, Font Font, Color Color) 
Draws text in the given font and color at the given position.
DrawTile (float X, float Y, float XL, float YL, float U, float V, float UL, float VL, Material Material, Color Color) 
Draws a material tile on the ScriptedTexture at the given X/Y position, stretched to XL/YL pixels, and taken from the area specified by U/V (horizontal/vertical texel offset) and UL/VL (width/height) from the given material.
SetSize (int Width,int Height) 
Sets the size of the ScriptedTexture.
TextSize (coerce string Text, Font Font, out int Width, out int Height) 
Returns the size of the given text in the given font in the out parameters Width and Height.

Creation in Code

A simple example of creating a new scripted texture for an actor dynamically at runtime.

<uscript> var protected ScriptedTexture MyScriptedTexture; var protected string MyMessage; var protected const Font MyFont; var protected const color MyFontColor;

event PostBeginPlay() {

 // Allocate a new scripted texture from the pool
 // and have it call us for updates.
 MyScriptedTexture = ScriptedTexture(
   Level.ObjectPool.AllocateObject( class'ScriptedTexture' ) );
 MyScriptedTexture.SetSize( 256, 256 );
 MyScriptedTexture.Client = Self;
 // Attach the texture to one of the actors
 // skin materials.
 Skins[0] = MyScriptedTexture;
 SetMessage( "Hello Texture!" );


event Destroyed() {

 // You should disconnect the object 
 // pool texture from everything you've
 // assigned it to.
 Skins[0] = None;
 // Clean up else you will leak resources.
 assert( MyScriptedTexture != None );
 Level.ObjectPool.FreeObject( MyScriptedTexture );
 MyScriptedTexture = None;


function SetMessage( string NewMessage ) {

 // Change the message and force an update
 // of the scripted texture on the next 
 // frame it's visible.
 MyMessage = NewMessage;
 assert( MyScriptedTexture != None );


event RenderTexture( ScriptedTexture Tex ) {

 local int w, h;
 assert( Tex == MyScriptedTexture );
 // Draw the text centered.
 Tex.TextSize( MyMessage, MyFont, w, h );
 Tex.DrawText( ( Tex.USize / 2 ) - ( w / 2 ),
   ( Tex.VSize / 2 ) - ( h / 2 ),
   MyMessage, MyFont, MyFontColor );


defaultproperties {


} </uscript>

Shambler: Scripted textures have a problem with rendering maps containing skyboxes when UseStencil is set to True in UT2004.ini but when UseStencil is False warp zones and some other things stop working, here is a little hack I coded which gets them to work together :)

<uscript> simulated event RenderTexture(ScriptedTexture Tex) { local RenderDevice rDev; local string sInitVal;

// Lovely hack for scripted textures :) rDev = GameEngine(FindObject("Package.GameEngine", Class'GameEngine')).GRenDev;

sInitVal = rDev.GetPropertyText("UseStencil"); rDev.SetPropertyText("UseStencil", "False");

// Draw stuff

rDev.SetPropertyText("UseStencil", sInitVal); } </uscript>

Creation in UnrealEd

This page describes how to make a ScriptedTexture in UnrealEd and draw some text on it with script: Writing On ScriptedTextures.