Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 11, 2013 at 10:19 AM by luckruns0ut for the following reason:

Duplicate Question

avatar image
0
Question by luckruns0ut · Apr 10, 2013 at 08:27 PM · c#pathfindingnavigation

Object reference not set to instance of object - Can't find solution.

Hi, I've been having a nightmare trying to get this script sorted out and it's slowly going in the right direction, but when I try and solve the path, for some reason I get the following error:

NullReferenceException: Object reference not set to an instance of an object AStarSolver.GetNodeWithLowestTotal (System.Collections.Generic.List`1 list) (at Assets/Scripts/AStarSolver.cs:126) AStarSolver.Solve (Vector3 startPos, Vector3 endPos) (at Assets/Scripts/AStarSolver.cs:52) DrawPaths.Update () (at Assets/Scripts/DrawPaths.cs:24)

I know that this means I'm trying to access something that hasn't been set, but I don't know why this is.

I'd appreciate it if someone could read it and tell me what's up with it.

http://pastebin.com/74iywYsn the pathfinder.

EDIT: I also want to point out that the grid is generated before anything else is ran, and it still errors out.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image luckruns0ut · Apr 10, 2013 at 08:41 PM 0
Share

An index?

avatar image Loius · Apr 10, 2013 at 08:42 PM 0
Share

you so fast. yeah, an index:

 for ( int i = 0; i < list.Count; i++ ) {
   openNode = list[i];
avatar image luckruns0ut · Apr 11, 2013 at 10:20 AM 0
Share

Didn't know that was called an index :P Thought that was just called a for loop

1 Reply

  • Sort: 
avatar image
0

Answer by Loius · Apr 10, 2013 at 08:42 PM

change the foreach @ ~126 to an index for and see if that helps. // nevermind, should be fine. foreach (x in y) essentially makes x read-only, but you're not writing so shouldn't be a problem.

also GetNode will gleefully return null with no message, and vector comparisons can be inexact. since you're .Add-ing the result of GetNode with no test for null, it's very possible to be .Add-ing nulls into the list.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image luckruns0ut · Apr 10, 2013 at 08:42 PM 0
Share

What is an index? Never came accross that before...

avatar image luckruns0ut · Apr 10, 2013 at 08:43 PM 0
Share

And by the way, the vectors are rounded to floor(so anything with a decimal, even ones above .5 will be rounded downwards so that the vectors will match)

avatar image Loius · Apr 10, 2013 at 08:45 PM 0
Share

but what if there isn't a node there at all?

i'd say just add a debug.log at the end of that function - it should never return null; that's a case of 'I can't do what you asked'

avatar image luckruns0ut · Apr 10, 2013 at 08:49 PM 0
Share

hmm ive changed the return null to return a new node for now. Any idea how I can make it check for the closest node to a point? Like if I have a node at (300,0,50) and I try and get a node with (500,0,60), it would return the closest node: (300,0,50) for example? assu$$anonymous$$g that the (300,0,50) is the closest node

avatar image Loius · Apr 11, 2013 at 04:48 PM 0
Share

https://www.google.com/search?q=unity+closest+object

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a flying enemy ? 0 Answers

Making my own navmesh 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Link two nodes with a edge 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges