- Home /
Parenting a prefab
Hi,
I am trying to make a game like Frogger. When you jump on the log you move with log.
So I created a Prefab that's randomly being called and it move down the river.
My issue when I jump on the log, I get an error message saying :
Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption. UnityEngine.Transform:set_parent(Transform)
Here is the code to Instantiate the prefab:
var prefab:Transform; var Platform:Transform;
function appear () {
var position = Vector3(Random.Range(74.4, 76.2), 2, Random.Range(-8,-7));
var Platform= Instantiate(prefab,position, Quaternion.identity);
Here is the Parenting Code it is on the Player, The prefab is tagged as Platform :
var myplatformSides:GameObject;
function OnControllerColliderHit(hit: ControllerColliderHit) {
if(hit.gameObject.tag=="Platform"){
transform.parent=myplatformSides.transform; }
else
transform.parent=null; }
Thank you
Answer by Bunny83 · Jan 23, 2011 at 02:07 AM
My guess is that you bind a prefab to "myplatformSides" and you use this prefab reference like a GameObject instance. I think you want to do something like:
function OnControllerColliderHit(hit: ControllerColliderHit) {
if(hit.gameObject.tag == "Platform"){
transform.parent = hit.gameObject.transform;
}
else
transform.parent = null;
}
or can you explain for what you use the "myplatformSides" variable? Is it set to an instance of your prefab?
You are right I did bind it.
And your correction Works Perfectly.
Thank You