- Home /
Question by
BloodAsp · Dec 13, 2014 at 10:55 AM ·
javascriptprefabinstances
Prefab being altered by changes implemented to instances at run time
When I instantiate this prefab i have a code attached that deletes certain parts, when i then instantiate another copy the pieces removed from the previous instance are also missing from the new instance.
#pragma strict
function Start() {
yield WaitForSeconds (0.1);
Destroy (this);
}
function OnTriggerEnter(collision: Collider) {
if (collision.gameObject.tag == "Real") {
Destroy(gameObject);
}
}
The code in question
Comment
#pragma strict
var Class1Piece : GameObject;
var GhostClass1Piece : GameObject;
var SpawnPoint : Transform;
var GhostCurrentPiece : GameObject;
var CurrentPiece : GameObject;
var $$anonymous$$ainController : GameObject;
var GhostSpawn : int = 0;
var GhostSpawned : boolean;
var Spawned : boolean;
var PieceIdentNumber : int;
var $$anonymous$$ouseEntered : boolean;
function Start () {
$$anonymous$$ainController = GameObject.Find("Controller");
}
function Update () {
PieceIdentNumber = $$anonymous$$ainController.GetComponent(ControllerScript).SelectedComponent;
}
function On$$anonymous$$ouseEnter () {
$$anonymous$$ouseEntered = true;
if ((PieceIdentNumber == 1) && (GhostSpawned == false) && (Spawned == false)){
GhostCurrentPiece = Instantiate(GhostClass1Piece, SpawnPoint.position, SpawnPoint.rotation);
GhostSpawned = true;
}
}
function On$$anonymous$$ouseExit () {
$$anonymous$$ouseEntered = false;
Destroy (GhostCurrentPiece);
GhostSpawned = false;
}
function On$$anonymous$$ouseDown () {
if ((PieceIdentNumber == 1) && (Spawned == false)){
yield WaitForSeconds (0.3);
CurrentPiece = Instantiate(Class1Piece, SpawnPoint.position, SpawnPoint.rotation);
Spawned = true;
}
}
This is the code used to instantiate The prefab in question would plug into the class1piece variable.
it should look like Fine but with another stacked on top
fine.png
(57.8 kB)
notfine.png
(91.5 kB)
Answer by SkaredCreations · Dec 13, 2014 at 11:00 AM
If you're using Instantiate passing the first instance instead of the original prefab then it's true of course. Else post your code of Instantiate.
Your answer
![](https://koobas.hobune.stream/wayback/20220613173908im_/https://answers.unity.com/themes/thub/images/avi.jpg)