PDA

View Full Version : Weird issue with setMaterial



xtr33me
03-17-2011, 07:14 PM
Unsure if there is maybe something that I am jsut missing here. I currently have the below config and when I destroy a block I want to simply set a random material from my array to the blocks. What is happening is sometimes the material is not showing. I see that the wireframe block is there but there is no material showing, it just looks invisible. Am I applying this incorrectly? Is there something I can test to see if the call loaded the material correctly? Now it seems every time I start the game, which is using the PreBeginPlay method, all the blocks seem to have a meterial. It seems to only be when I call SetRandomColor elsewhere that it intermittantly will set a block to no color. I was also logging out the index at one point, but the indexes were always valid and it wasn't always with the same color index.



var MaterialInstanceConstant myMatInst;

simulated function PreBeginPlay()
{
MyBlockMats[0] = Material'CubeFectionPackage.Mats.Mat_Blue';
MyBlockMats[1] = Material'CubeFectionPackage.Mats.Mat_Green';
MyBlockMats[2] = Material'CubeFectionPackage.Mats.Mat_Grey';
MyBlockMats[3] = Material'CubeFectionPackage.Mats.Mat_Orange';
MyBlockMats[4] = Material'CubeFectionPackage.Mats.Mat_Purple';
MyBlockMats[5] = Material'CubeFectionPackage.Mats.Mat_Red';
MyBlockMats[6] = Material'CubeFectionPackage.Mats.Mat_Yellow';
}

simulated function PostBeginPlay()
{
myMatInst= new(self) class'MaterialInstanceConstant';
self.SetRandomcolor();
}

function SetRandomcolor()
{
if(myMatInst != none)
{
myMatInst.SetParent(MyBlockMats[Rand(7)]);
StaticMeshBlock.SetMaterial(0,myMatInst);
}
}

xtr33me
03-18-2011, 06:58 AM
Is there anything I am doing wrong with my code that would cause this? These methods are in my block class itself and I am calling this setRandomColor method on many blocks quickly. In otherwords, when I destroy a row of blocks, I don't really destroy them, I just hide them move their location and have them call their SetRandomColor method. And what is strange is it is intermittant, there are no errors that I can see and it works on most of the blocks just not all of them always.

ambershee
03-18-2011, 07:03 AM
A) Why are you not defining the contents of your array in the default properties?
B) Use a MaterialInterface variable, rather than a MaterialInstance.
C) I suspect your hard referenced materials may not have the correct paths, but it can be hard to tell. It may just not like you assigning an MIC variable a material path.

xtr33me
03-18-2011, 05:15 PM
Thanks for the response ambershee. I will check out that type when I get home from work tonight. I figure the path to the materials is correct because for most of the 70 blocks on screen, I have materials showing and for all the colors in fact. Actually on startup, as stated before, all the blocks have random colored materials assigned. It is only when I start calling SetRandomColor on my moving of block positions that it will intermitantly sometimes show no mat applied to a single block. Will post back with results later. Thanks!