Hello Guest

Author Topic: Can't access to tk2dTileMap.renderData from Prefabs  (Read 4250 times)

fenixn0909

  • Newbie
  • *
  • Posts: 2
    • View Profile
Can't access to tk2dTileMap.renderData from Prefabs
« 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!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Can't access to tk2dTileMap.renderData from Prefabs
« Reply #1 on: June 10, 2015, 09:47:31 am »
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.

fenixn0909

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Can't access to tk2dTileMap.renderData from Prefabs
« Reply #2 on: June 10, 2015, 02:35:36 pm »
It works and another lesson learnt, thank you very much for point it out! you saved my day!  :D