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 Jan 28, 2012 at 04:29 AM by Tasarran for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Tasarran · Jan 24, 2012 at 08:19 PM · arrayarrayspathfindingpath-finding

Array of variable-length arrays (JS)

Here's a capsule version of my problem:

Working on a tile-based game; I want to select a unit and calculate all paths for that unit to any hex it can reach.

I do this by doing essentially two layered pathfinding routines, the first one simply picks the first object off an open list, then calls an A-Star routine to calculate the move cost to that hex. If it is more than the moves available, the outer loop moves on. If it is movable, the outer loop adds its neighbors to the open list, and moves to the next item on the open list. When it is done, it has found all the paths, and the A-Star part has stored the paths in an array on each hex, ready and available to use on demand, as MouseOver to highlight the path.

This is working perfectly, but it is slow. It takes 8-10 seconds to process each selection, which is obviously not workable.

What I would like to do is modify my A-Star so that it can do all the paths at the same time. The problem is that my A-Star uses variables on the map hexes themselves, so I basically need to change any variables A-Star uses into arrays, and have one for each potential path on the board. No problem for the variables that are singletons, GCost becomes GCost[MapSize], but when it comes to the Open and Closed list arrays that A-Star is using, I'm at a loss for how to deal with it.

Essentially, I want make an array of a fixed size, each element of which is an array of variable size.

I know I'm close, but everything I have read about how to approach this has confused the heck out of me... I know I'm not stupid, I'm just having trouble getting my head around the proper syntax to do what I want.

PS: if anyone has any better ideas how to multi-thread this pathfinding, I'm completely open to the possibility that what I'm asking might not be the best answer... ;)

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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Tasarran · Jan 24, 2012 at 09:49 PM

I figured it out. If you are interested, here is a section of test code.

var One: GameObject; var Two: GameObject; var Three: GameObject;

function Start () { // define a JS Array var JSArray = new Array(); // define a Unity array var Builtin = new Array[3];

 // add some stuff to the JS array
 JSArray.Add(One);
 JSArray.Add(Two);
 JSArray.Add(Three);

 // assign the JS array to index 0 of the Unity array
 Builtin[0] = JSArray;

 // prints the three objects in System
 Debug.Log(JSArray);
 // prints the copy of System that was assigned
 Debug.Log(Builtin[0]);

 // shows that you can still use the array commands on the items inside the Unity array
 Builtin[0].Add(One);
 Builtin[0].Add(Two);
 Builtin[0].Add(Three);
 //  prints the six objects in the array now
 Debug.Log(Builtin[0]);

}

Comment
Add comment · Show 3 · 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 Peter G · Jan 31, 2012 at 12:24 AM 2
Share

System just might be the worst possible variable name except for var. Its a namespace and it makes much harder to read because it looks like you are trying to access a namespace when you really aren't.

avatar image syclamoth · Jan 31, 2012 at 12:38 AM 0
Share

Yeah, seriously fix that.

avatar image Tasarran · Jan 31, 2012 at 11:21 AM 0
Share

Seriously? Pedantic much? This was just an example to show syntax. But I've removed the offensive variable name...

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Find a path with specific steps (moves) on a grid 0 Answers

IndexOutofRangeException 1 Answer

XML File, or Array? 1 Answer

Multidimensional array trouble 2 Answers

Prefabs instantiated from an array are keeping their public int value 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