- Home /
[SOLVED] Problem rendering prefab model in game
I created a prefab with an fbx model and some other components like scripts etc. I can drag and drop the prefab into the scene view and I can see the model just fine...it even animates. If I open the game I still see that prefab that I dropped into the scene.
But when I try to instantiate the prefab using a c# script I do not see the model. Not even the labels that are supposed to appear above the object's head show up.
Why does this happen?
Does the instantiated prefab appear in the hierarchy view? $$anonymous$$aybe it's in the game, but not somewhere the camera can see it?
Thanks for the replies so far guys. Here is the else if block where the local character is instantiated. This script worked fine with a 2d sprite but I decided to make my game in 3d ins$$anonymous$$d, so I totally re-made the prefab this time with a 3d model. And yes, the prefab does appear in the hierarchy view when this block of code is called. I just cant see the model when I instantiate it.
else if (tempHash.Contains$$anonymous$$ey(current_char))//for the current user's client
{
//create a new instance of the player
THISplayer = (GameObject)Instantiate(Resources.Load("playerPrefab"));
THISplayer.name = cachename;
player_data _playerData = THISplayer.GetComponent<player_data>();
//cache player data variables
_playerData.OtherCharName = cachename;
_playerData.gender = cc_gender;
_playerData.race = cc_race;
//set the last known position of the character from the database
THISplayer.transform.position = new Vector3((float)tempD[1], (float)tempD[2], (float)tempD[3]);
//get all character data from the server that does not belong to this client
RequestAllOtherCharData();
//initialize player components for this client
THISplayer.GetComponentInChildren<Camera> ().enabled = true;
THISplayer.GetComponent<player_controller> ().enabled = true;
_THISpdata = GameObject.Find(current_char).GetComponent<player_data>();
}
found that the model is being rendered but it not in the camera view...not sure why yet.
Answer by jaja1 · Oct 26, 2014 at 08:14 PM
Solved: the mesh, bones and camera had to be realigned with each other since they were all children of the same game object.
Answer by jabez · Oct 26, 2014 at 01:20 AM
Click the root of the player & under the skin mesh renderer check update when off screen 
That was actually unchecked. I checked it but the problem still persists. I also checked to see if the change was applied in game and it was :/ PS. Is it a problem to have the skinned mesh as a child of the prefab?...thats how the prefab was created.
Answer by jctz · Oct 26, 2014 at 05:29 AM
Maybe check the gameobject's layer and make sure it's not being modified by code and now being culled by the camera?
I do not believe it is a culling issue as you can see in the attachment. And as I said I did check earlier with a second client that the model is being rendered but it is way off from the camera view. 
sorry to keep bumping but I'm still trying to figure it out and no luck :/
Your answer