- Home /
"Prefab GameObject's can not be made active!" - Need a fix
Hey guys, feel like i've made a rookie error here. I'm putting together a small FPS game, and ran into a little problem.
The error is occuring on the "OutsideView.SetActiveRecursively" line from the chunk bellow...
*public GameObject OutsideView;
public Vector3 CurrentPosition;
public Quaternion CurrentRotation;
void Start()
{
DontDestroyOnLoad(gameObject);
ControllerTransform.gameObject.SetActiveRecursively(false);
OutsideView.SetActiveRecursively(false);*
I'm getting the error "Prefab GameObject's can not be made active! (carl)"
carl is the name of my character model, inside the first person controller.
I have a feeling that i should Instantiate it, but am completely lost as how to do so. If anyone knows how to fix this problem, would be great to hear from you!
Cheers.
Answer by Julien-Lynge · Jan 30, 2013 at 03:23 PM
The prefab doesn't actually exist in your game, so that message is correct, and you're correct that you have to instantiate it first.
Luckily, you can just call Instantiate on the prefab and save the result, like so:
GameObject instantiatedObj = Instantiate(myPrefab) as GameObject.
The 'as GameObject' at the end casts to a GameObject - Instantiate returns a more generic Object. Then, you can play with instantiatedObj without getting errors.
BTW: If you're using Unity 4.0, you probably don't want to use SetActiveRecursively anymore, since it's been deprecated - try SetActive instead.
Simple, was using Unity 4.0
Such a simple fix, remove part of a word and its done, shame there was nothing clear about this in the scripting reference. (that or i'm just blind)
Thank you very much Julien :)