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 /
avatar image
0
Question by demilp · Dec 10, 2012 at 11:41 PM · pathfindingalgorithmnode

Making a list of list of nodes for Kruskal

I'm trying to do a Kruskal algorithm (pathfinding), but I'm having a problem when putting the nodes list in the list of list of nodes (each node is in a separate list and as the nodes connect, the lists are combined).

Here is my code:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Kruskal : MonoBehaviour {
     
     
     public List<List<Nodo>> bosque;
     public GameObject[] goNodos;
     public List<Nodo> nodos;
     
     
     void Start () {
         goNodos = GameObject.FindGameObjectsWithTag("Nodo");
         
         for (int i = 0; i < goNodos.Length; i++) {
             nodos.Add(goNodos[i].GetComponent<Nodo>());
         }
         
         
         for (int i = 0; i < nodos.Count; i++) {
             bosque[i].Add(nodos[i]); //It throws an error here. (NullReferenceException: Object reference not set to an instance of an object)
         }
         
         
     }
     
 
 }




What am I doing wrong?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 10, 2012 at 11:46 PM

Where do you actually create your lists? So where do you actualy do

 bosque = new List<List<Nodo>>();

and where do you fill the list with lists?

something like that:

 bosque.Add(new List<Nodo>());
 bosque.Add(new List<Nodo>());
 bosque.Add(new List<Nodo>());

Lists don't grow on trees, they have to be created ;)

Comment
Add comment · 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
0

Answer by demilp · Dec 10, 2012 at 11:57 PM

Great! Solved! Is there any way to visualize it in the inspector?

Comment
Add comment · Show 1 · 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 Bunny83 · Dec 11, 2012 at 12:05 AM 0
Share

That's not really an answer... Did you mean to post a comment? If not and you had another problem which you solved in a different way, post what you did.

Visualize what? the List of List thing? Not be default because Unity can't serialize such a construct. The default inspector only displays things which are serializable by Unity.

However, you can create a custom inspector for your class. It's not that hard to create one, but also not as easy as the usual Unity stuff ;) See Extending the Editor

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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

A* optimization and path help 0 Answers

A* Algorithm Node Grid Generation 2 Answers

Unity 3.5: What is the definition of PLE algorithm? 1 Answer

Preventing lines from overlapping 1 Answer

Help with A* algorithm 0 Answers


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