Question by
OfekSha · May 30, 2021 at 11:58 PM ·
editoreditor-scriptingprefab-instanceplaymodearray of gameobjects
Storing array of game objects in editor mode and click play corrupt the array.,Can't get game object from array after click on the start.
I am trying to store game objects in some array, but after the start button clicked all the game objects change and I can't get the references anymore from my array.
I am new in unity programming and all the changes I am doing are in the editor mode.. I am using editor class and call methods from OnInspectorGUI().
[CreateAssetMenu(fileName = "Grid2D", menuName = "Grid/2D", order = 1)]
public class Grid2D : ScriptableObject
{
private GameObject gridGameOject;
public Transform[,] grid = new Transform[25, 25];
public GameObject tile;
void createTile(int x, int y)
{
Vector3 position = Vector3.zero;
Bounds sprite_rendr = tile.GetComponent<SpriteRenderer>().bounds;
position.x = sprite_rendr.size.x*x;
position.y = sprite_rendr.size.y*y;
GameObject cube = (GameObject)PrefabUtility.InstantiatePrefab(tile);
cube.transform.SetParent(gridGameOject.transform, false);
cube.transform.localPosition = position;
grid[x, y] = cube.transform;
}
}
Comment
Your answer
Follow this Question
Related Questions
Array does not serialize properly in a prefab instance for a scene 0 Answers
Dragging prefab onto object through code 1 Answer
Editor script: Variable created on gameObject in editor set to missing on runtime 0 Answers
Why does GameObject.FindWithTag() get a wrong instance? 2 Answers
Unity5-serializedObject.FindProperty("listname") for ReorderableList doesn't work... 2 Answers