Quantcast
Channel: Questions in topic: "error message"
Viewing all articles
Browse latest Browse all 2891

Array of dictionaries: "Object reference not set to an instance of an object"

$
0
0
Hi, I'm trying to have an array of dictionaries (which has GameObject references as its keys and Vector3s as its values), where each index in the array refers to one "step" in time (each "step" refers to one move within the game), so that I can then use this to create a simple "undo" feature, where the player can press z to undo his previous action, which would mean the game would first get the dictionary at the previous array index, then iterate through this array, setting each GameObject to its position, which was recorded as its corresponding value in the dictionary. Unity doesn't seem to be having a problem with how I am using the array of dictionaries, but rather with how I am referring to the objects in some way. Here is the relevant code: object[] all_objects; int step; Dictionary[] positions_record; [...] void Record() { all_objects = FindObjectsOfType(typeof(GameObject)); Dictionary record_dictionary = new Dictionary(); for (int i = 0; i < all_objects.Length; i++) { GameObject obj = (GameObject) all_objects[i]; if (obj.activeInHierarchy && obj.tag != "ladder") { record_dictionary.Add(obj, obj.transform.position); } } positions_record[step] = record_dictionary; } Record() gets called in Start() as well as after every move that the player makes. However, every time it is called, Unity throws the following error message: NullReferenceException: Object reference not set to an instance of an object (wrapper stelemref) object:stelemref (object,intptr,object) Any help would be much appreciated.

Viewing all articles
Browse latest Browse all 2891

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>