I’ve looked through the forums to try to find an answer to this but I can’t find anything on it :s
When instantiating a prefab I seem to get an empty “New Game Object” appear in my scene along with the cloned prefab and I have no idea why. It’s not so much a problem, it’s just a strange behaviour.
Here’s what I’m doing :
(I’m not able to test this code right now so it may have some minor mistakes :P)
GameObject player = Instantiate( Resources.Load("playerPrefab"), Vector3.zero, Quaternion.Identity ) as GameObject;
When I look in the scene heirachy I get “playerPrefab (clone)” but also an empty “new game object”
the ‘player’ object in the code is properly assigned and functions correctly so like I said, it doesn’t cause problems.
Iv’e tried writing this in several different way but all give me the same result…
public GameObject playerPrefab; //Drag prefab here in inspector
GameObject player = Instantiate(playerPrefab, Vector3.zero, Quaternion.Identity);
Object[] playerPrefabs = Resources.LoadAll("playerPrefabs"); //Loads all resources from "Resources/playerPrefabs" into object array;
GameObject player = Instantiate(playerPrefabs[0], Vector3.zero, Quaternion.Identity);
and I’ve even tried not returning the instance in code, eg:
Instantiate(Resources.Load("playerPrefab"), Vector3.zero, Quaternion.identity) as GameObject;
Can anyone shed some light on this wierd functionallity?