2D Toolkit Forum
2D Toolkit => Support => Topic started by: fenixn0909 on June 10, 2015, 03:14:49 am
-
Hi all,
I have some tilemap Prefab store in Resource folder, I would like to reparent the renderDatas to WorldMap, here is the code:
GameObject WorldMap;
GameObject tk2dTileMapPrefab = (Resources.Load("Prefabs/tileMapArea1") as GameObject);
Instantiate (tk2dTileMapPrefab, new Vector3 (0, 0, 0), Quaternion.identity);
tk2dTileMap tilemap = tk2dTileMapPrefab.GetComponent<tk2dTileMap>() as tk2dTileMap;
tilemap.renderData.transform.parent = WorldMap.transform;
there is no compiling error, but when the game start to run, the error message shows up:
UnassignedReferenceException: The variable renderData of tk2dTileMap has not been assigned.
You probably need to assign the renderData variable of the tk2dTileMap script in the inspector.
Is this a bug? or am I missed something to make this work? ???
Thanks in advanced!
-
Thats expected - the render data doesn't exist in a prefab. Once instantiated, you should be able to get the data, but you're not storing the gameobject after instantiating... You'll need to do that and get the render data from the instantiated prefab.
-
It works and another lesson learnt, thank you very much for point it out! you saved my day! :D