- Home /
Code works in Editor but not in standalone
void GenerateBlankMap(int mSize)
{
mapSize = mSize;
//Clear any children that may exist
for (int i = 0; i < parent.childCount; i++)
{
Destroy(parent.GetChild(i).gameObject);
}
map = new List<List<Tile>>();
for (int x = 0; x < mapSize; x++)
{
List<Tile> row = new List<Tile>();
for (int y = 0; y < mapSize; y++)
{
//Create a tile set its position,
//Add it to the row list,
//Set tiles parent to be this gameobject
Tile tile = ((GameObject)Instantiate(PrefabHolder.instance.TILE_BASE_PREFAB,
new Vector3(x - Mathf.Floor(mapSize / 2), 0,
-y + Mathf.Floor(mapSize / 2)),
Quaternion.Euler(new Vector3()))).
GetComponent<Tile>();
tile.gridPosition = new Vector2(x, y);
tile.SetType(TileType.Grass);
row.Add(tile);
tile.transform.SetParent(parent);
}
map.Add(row);
}
}
This code works fine in the editor but when I build it out for standalone use its gives a me a null reference exception when it reaches the Instaniate. Any help on solving this problem would be greatly appreciated.
Is is because the PrefabHolder.instance.TILE_BASE_PREFAB or the PrefabHolder.instance is equal to null? If so, maybe you should check that when and how these values are being assigned.
Answer by darcerail · May 06, 2015 at 03:38 PM
Solved the problem. Just called the GenerateBlankMap function in the Start function instead of Awake.
Your answer
Follow this Question
Related Questions
Attach script twice. 1 Answer
initial velocity for instantiated ragdoll prefab 1 Answer
NullReferenceException: I think unity bug 3 Answers
Store Instantiated Object script reference 2 Answers
NullReferenceException? 1 Answer