- Home /
What is this error and how can I fix it?
Ok, so I am trying to make a character customization screen, where you can change clothes, height, and skin color and whatnot. And I am having a lot of trouble with the changing in faces and skin color, for each thing there is the same error.
MissingComponentException: There is no 'Renderer' attached to the "PC" game object, but a script is trying to access it. You probably need to add a Renderer to the game object "PC". Or your script needs to check if the component is attached before using it.
Here is the code i am using for the skin color. Is there something I should add or something I am not doing right?
Any help would be awesome! Thanks
public void LoadSkinColor() { characterMaterialMesh.renderer.materials[ (int)CharacterMaterialIndex.Face ].mainTexture = Resources.Load( GameSetting2.HEAD_TEXTURE_PATH + "head_" + GameSetting2.LoadHeadIndex() + "_" + GameSetting2.LoadSkinColor() + ".human") as Texture; }
For starters, try adding a mesh renderer to the pc object. Looks like Bergzerg's stuff.
Better suggestion: For starters, try entering your code in a code block, with the button with "101010" on it, so we can read it easier. But yeah, like voncarp said, you need to add a $$anonymous$$eshRenderer component to the object named "PC." To do that, at least the easiest way, select the GameObject in your hierarchy, and under the "Component" menu, at the top, select "$$anonymous$$esh" then "$$anonymous$$eshRenderer."
Good luck!
I am a self admitting noob. So thank you both for the help. I will be sure to put the code like that next time. And yes voncarp, it is from his tutorial series. Since your familiar with it, maybe you can help me, it indexes through the faces, I can tell via debug, but the actual face on the character does not change.
Here is most of the code for the face changer.
public static void ChangeHeadIndex( int index ) { headIndex = index;
// Debug.Log( "Head set to index: " + headIndex ); _update = true;
}
Below is where the error takes me.
public void UpdateHead() { head$$anonymous$$aterial = PC.Instance.character$$anonymous$$aterial$$anonymous$$esh.renderer.materials[4]; //4 is the index of the material for the head/face texture head$$anonymous$$aterial.mainTexture = Resources.Load( GameSetting2.HEAD_TEXTURE_PATH + "head" + headIndex + "" + skinColor + ".human") as Texture;
There is no error for the muscular character, but there is for the fat character.
This is the error I get.
IndexOutOfRangeException: Array index is out of range. Player$$anonymous$$odelCustomization.UpdateHead () (at Assets/_Scripts/Character/Character Customization/Player$$anonymous$$odelCustomization.cs:130) Player$$anonymous$$odelCustomization.Update () (at Assets/_Scripts/Character/Character Customization/Player$$anonymous$$odelCustomization.cs:59)
Even though I dont get an error for the muscular character, the face still doesn't change. I'm just not sure what the problem is.
Its tough to answer as is could be a number of different problems. At this particular section in his tutorial you have to have a a few different areas set up properly for it to work. Your problem here might be that your models and gameobjects need to be named properly and your resource folder needs the exact folders and number of textures to be set up exactly how he sets it up in the tutorial and also based on the path in the gamesettings2.
Answer by justinl · Sep 15, 2012 at 05:26 PM
As Voncarp said, add a MeshRenderer component to the GameObject named "PC".
I'm simply pasting this answer here so that the question can be marked as "Answered". If either of the original guys who answered the question want the points feel free to post your answer officially and I'll delete this one.
Answer by ReK Project · Jan 04, 2013 at 07:10 AM
The problem is that if you are using a later version of frogames commoners and warriors, they use only one material for the character mesh instead of 5 like in the version petey is using.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Error or Bug in unity 0 Answers
When I kill one enemy, the rest disapear, but still shoot 1 Answer
Invalid Characters in Path 1 Answer