Color
The type color is not a built-in type, but a struct defined in the Object
()class of all Unreal Engine games.
The color struct is used for drawing certain things with the Canvas and HUD with a specified color that is set with the 4 members of type byte(or float for LinearColor struct) which are R(Red), G(Green), B(Blue) and A(Alpha).
Note: Unreal Engine 3 games may also define other color-like structs, such as LinearColor.
Color operations
In Unreal Engine 2 there are no built-in operators for color structs except a few in Actor.
Making a color
Unreal Engine 3 provides a MakeColor()
function in Object that can be used to make a color struct instance by passing independant RGBA components e.g.
local Color BlueColor;
BlueColor = MakeColor( 0, 0, 255, 255 );
this will create a blue color and assign it to BlueColor.
Note: Unreal Engine 2 doesn't have function MakeColor()
accessible from the Object class, but instead in the Canvas class, so change the MakeColor()
code to Class'Canvas'.static.MakeColor()
.
Color operators
Unreal Engine 3 provides the -
*
+
operators for colors and Unreal Engine 2 only provides them if extending from Actor.
-
Substracts a color by another color e.g.
local Color BlueColor;
local Color BlackColor;
BlueColor = MakeColor( 0, 0, 255, 255 );
BlackColor = BlueColor - MakeColor( 0, 0, 255, 255 );
Subtracts the blue color from BlueColor and would become a black color assigned to BlackColor.
*
Multiplies a color by the scalar (i.e. float) value e.g.
local Color BlueColor;
BlueColor = MakeColor( 0, 0, 255, 255 );
BlueColor = BlueColor * 0.5f;
Multiplies BlueColor by half thus BlueColor will become darkblue.
+
Adds a color to a color e.g.
local Color BlueColor;
local Color PurpleColor;
BlueColor = MakeColor( 0, 0, 255, 255 );
PurpleColor = BlueColor + MakeColor( 255, 0, 0, 255 );
Merges BlueColor with a red color and becomes purple then assigns to PurpleColor.
Performance
Because the above operators are slow it is recommend to convert them to a Vector first and then use the vector operators instead of the color operators when you are making use of the same color and same operators a lot in one function.
Utilities
Because of the lack of many color operations you can view a list of community made color operations at UnrealScript utils to use in your project.
See also
Declarations | Preprocessor • Classes • Interfaces • Cpptext • Constants • Enums • Structs • Variables (Metadata) • Replication block • Operators • Delegates • Functions • States • Defaultproperties (Subobjects) |
---|---|
Types | bool • byte • float • int • name • string • Object • Class • Enums • Structs (Vector ⋅ Rotator ⋅ Quat ⋅ Color) • Static arrays • Dynamic arrays • Delegates • Typecasting |
Literals | Boolean • Float • Integer • Names • Objects (None ⋅ Self) • Vectors • Rotators • Strings |
Flow | GoTo • If • Assert • Return • Stop • Switch • While • Do...Until • For • ForEach • Break • Continue |
Specifiers | Super • Global • Static • Default • Const |
UnrealScript | Syntax • .UC • .UCI • .UPKG • Comments • #directives • Native |