Quantcast
Channel: Questions in topic: "crash"
Viewing all articles
Browse latest Browse all 2383

Unity crash when deleting list

$
0
0
Hello all, I almost finished my pathfinding algorithm and now I am making the A* pathfinding recalculate a path because in my game the player will move a lot (2d top down game) and there will be a lot of obstacles that will be created on runtime. I made a simple system that works like this: -if the target has changed position (I check this by seeing if the closest node of the target has changed) and a path was found or the target s position has been reached so it will be if(changed_node && (found_path || reached_des)) -Clear the open list, the list that contains the nodes of the path, the list of the adjacent nodes (adjacent to the nodes of the closed list and of the path,the ones that are analyzed) and the closed list. -Finally call the function FindPath that is the path finder the problem is at the 2nd point, when I delete the closed_list unity crashes and it's not only a unity's problem because I builded the game and I saw that also in game it crashed when deleting the closed list. I really have no idea why it happens. A possible motivation that came to my mind is that the class that handles the movement costs of the nodes uses the closed list to find the G cost. I tried to disable this script but it didn't work. Here's the part of code. // Update is called once per frame void Update() { //launches pathfinding actual_node.my_node is the start node //targ_node.my_node is the target's closest node FindPath(actual_node.my_node, targ_node.my_node); //if the path was created follow the path if (path_nodes.Count > 0 && current_node < path_nodes.Count) FollowPath(); if (target.GetComponent().changed_node && (reached_dest|| found_path)) { found_path = false; reached_dest = false; path_nodes.Clear(); open_list.Clear(); adjacent_nodes.Clear(); //crashes here closed_list.Clear(); FindPath(actual_node.my_node, targ_node.my_node); } } found_path is true when a path is found in FindPath(), reahed_dest is true when the npc finished following the path to the target. What should I change to make it recalculate the path correctly? Thank you in advance for your help guys! :D

Viewing all articles
Browse latest Browse all 2383

Trending Articles



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