PDA

View Full Version : Assigning a shader in an expression


badtertle
04-30-2008, 07:13 AM
So, I have a unique project where I'm trying to create an in-maya game. I will give the players a number of characters to choose from, but they are all the same rig and geometry, just different accesories which visibility is toggled by an expression on an attribute on the main rig control.

On the same expression I am assigning different shaders. It works fine most of the time, but I keep getting these fatal errors when I switch characters. I'm not sure why its happening, but I assume it has to do with this texture switching.

Even if it doesnt, I really dont like the way i have this set up...heres a sample of the expression.

//robot
if (Main_Control.Character == 6)
{
NurseAccesories.visibility = 0;
WomanAccesories.visibility = 0;
AbeAccesories.visibility = 0;
RobotAccesories.visibility = 1;
NinjaAccesories.visibility = 0;

select CharacterA;
hyperShade -assign RobotShader;
select -cl;
}

is there any way to do the shader assignment just with nodes instead of having to do the selection bit? In the hypershade I cant see any connections from the shader to the model, so I'm not sure how to apply it there. Also, because it's an in-maya perspective window game, things like layered shaders probably won't do any good.

Also, if there are any other ideas what might make this scenario unstable to give me fatal errors every 8 or so times I switch....maybe a memory thing?? I dont' know..


Any help would be much appreciated.

meljunky
04-30-2008, 10:57 PM
The way you have the expression written that it will toggle the accesories, select the character, assign the shader and deselect the character for EVERY frame. You will want it to only run once.

-brian
www.meljunky.com (http://www.meljunky.com)

badtertle
05-01-2008, 04:07 AM
Good call...i think I'm going to add this code to my main game script instead of having it in an expression on the rig. It will be more inconvenient to create the animations, but at least it won't run every frame of the simulations.

CGTalk Moderation
05-01-2008, 04:07 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.