I’m instantiated some clones based off a prefab in my Resources folder when Start() is called in one of my other scripts. It instantiates fine, but when I exit, the clones persist, and if I click play again, they exist in the new run along with the newer clones. This only is happening for one prefab’s clones, my other prefab clones are destroying automatically when I exit play mode.
private IDable stageMarkerTemplate;
void SetUpMarkerLines() {
stageMarkerTemplate = Resources.Load<IDable>("Prefabs/Marker Line");
float xDist = GlobalVars.horizSize/GlobalVars.horizSecs;
for (int i = 1; i < GlobalVars.horizSecs; i++) {
SegmentHelper.snapLines.Add(new LineRepr(
-1 * GlobalVars.horizSize/2.0f + xDist * i));
Instantiate(stageMarkerTemplate,
new Vector3(-1 * GlobalVars.horizSize/2.0f + xDist * i + 1.5f,
GlobalVars.markerLineY,
0),
Quaternion.Euler(0, 0, 0));
}
}
void Start() {
...
SetUpMarkerLines();
...
}
The stageMarkerTemplate is the prefab that is being cloned. Anyone have any idea why this is happening and how I can change my code to have these clones automatically destroy when play mode is exited?