I wrote a LUA script to setup frame by frame animation, but if I try to change the material for a CSG brush during the game loop, it will not appear on the object in the game. I applied the same script I wrote to a sprite object and a cube model I exported from Blender and the material for each changed just fine during the loop. Am I doing something wrong for CSG brushes or is this a bug? Thanks!
Here is the script I wrote for testing purposes:
Script.speed = 10.0 -- float "Animation Speed"
Script.material1 = "" --path "Material (Frame 1)" "Material File (*mat):mat|Material"
Script.material2 = "" --path "Material (Frame 2)" "Material File (*mat):mat|Material"
Script.material3 = "" --path "Material (Frame 3)" "Material File (*mat):mat|Material"
Script.material4 = "" --path "Material (Frame 4)" "Material File (*mat):mat|Material"
Script.material5 = "" --path "Material (Frame 5)" "Material File (*mat):mat|Material"
Script.frames = 0
Script.currTime = 0.0
Script.currFrame = 0;
Script.mat1 = nil;
Script.mat2 = nil;
Script.mat3 = nil;
Script.mat4 = nil;
Script.mat5 = nil;
function Script:Start()
if(self.material1 ~= "") then self.frames = self.frames + 1; self.mat1 = Material:Load(self.material1); end;
if(self.material2 ~= "") then self.frames = self.frames + 1; self.mat2 = Material:Load(self.material2); end;
if(self.material3 ~= "") then self.frames = self.frames + 1; self.mat3 = Material:Load(self.material3); end;
if(self.material4 ~= "") then self.frames = self.frames + 1; self.mat4 = Material:Load(self.material4; end;
if(self.material5 ~= "") then self.frames = self.frames + 1; self.mat5 = Material:Load(self.material5); end;
end
function Script:UpdateWorld()
if(self.currTime >= self.speed) then
self.entity:SetMaterial(self.mat2)
self.currFrame = self.currFrame + 1;
if( self.currFrame > self.frames ) then
self.currFrame = 1
end
if( self.currFrame == 1 ) then
self.entity:SetMaterial(self.mat1)
end
if( self.currFrame == 2 ) then
self.entity:SetMaterial(self.mat2)
end
if( self.currFrame == 3 ) then
self.entity:SetMaterial(self.mat3)
end
if( self.currFrame == 4 ) then
self.entity:SetMaterial(self.mat4)
end
if( self.currFrame == 5 ) then
self.entity:SetMaterial(self.mat5)
end
self.currTime = 0;
else
self.currTime = self.currTime + Time:GetSpeed();
end
end