Hi Guys …
I have created some code, which basically dynamically creates a nodemap or grid for the use of pathfinding via an A* algorythm … It worked all fine and dandy, but now I wanted to create this nodemap pre-runtime via an editor script and save the nodemap in a gameobject or prefab for usage at runtime. This almost works like it should. I am able to create the nodemap, but when I try to store it in a gameobject the information concerning my custom class (Node) is somehow just lost in the process.
The snippets of my code, which concerns itself with the saving of the information can be seen here:
public class NodeMapCreator : MonoBehaviour {
[MenuItem ("GameObject/Generate NodeMap")] //Place the Generate Nodemap menu item in the GameObject menu
static void Init () {
Object prefab = EditorUtility.CreateEmptyPrefab("Assets/Nodemap.prefab");
List<Node> map = new List<Node>();
//List<int> ints = new List<int>();
int scaleX, scaleZ, sizeX, sizeZ, sizeY;
float radius, mSizeX, mSizeZ;
GameObject theMap;
GameObject aUnit;
LayerMask unitLayer = 1 << LayerMask.NameToLayer("Unit");
unitLayer = ~unitLayer;
theMap = GameObject.FindWithTag("Map");
aUnit = GameObject.FindWithTag("exampleUnit");
I then go onto actually creating the nodemap as a list of Nodes and then I try to store it in the following code:
GameObject theNodeMap = new GameObject();
theNodeMap.AddComponent<NodeMap>();
theNodeMap.GetComponent<NodeMap>().setVariables(map, sizeX, sizeZ, sizeY, radius, theMap, unitLayer);
theNodeMap.name = "NodeMap";
EditorUtility.ReplacePrefab(theNodeMap, prefab);
The funny thing is that the line:
theNodeMap.GetComponent().setVariables(map, sizeX, sizeZ, sizeY, radius, theMap, unitLayer);
is able to store all other variables, but just not my list of nodes (map). It just seems to disappear in my prefab.
Any ideas as to why this is? and what I could do to actually save my list of nodes? (nodemap)
Thanks in advance