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 Waldy · Aug 09, 2014 at 07:14 AM · lag

A* Pathfinding questions

I am making a tycoon game and i have chosen to use A* Pathfinding (http://arongranberg.com/astar/) for my AI as i found it so difficult making my own AI system. My tycoon game allows you to place down buildings and paths during runtime, so of course the A* Pathfinding grid has to be updated/scanned. So i added this piece of code "AstarPath.active.Scan();" to re scan every time i place down a path or building etc. The Pathfinding grid updated correctly, but the frame rate crumbles everytime it re-scans. Is there another way to re-scan which would hit my frame rate less, maybe scan in the general area?

Comment
Add comment · Show 2
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 tanoshimi · Aug 09, 2014 at 08:14 AM 0
Share

A* is generally used to find an efficient route between two nodes in a network - if you explain a little more why/how you are using it in your game we might be able to suggest alternatives (it's not obvious, to me at least, what part of a tycoon game needs graph analysis)

avatar image Waldy · Aug 09, 2014 at 10:41 AM 0
Share

Well the tycoon i am making is a Roller Coaster Tycoon inspired one. So you are able to place down rides, paths and trees. alt text

The above picture shows paths which i have placed down in during runtime. But because i placed down a new path the Pathfinding grid will have to be re-scanned to detect the newly added paths. I would want the Pathfinding grid to update maybe pretty frequently. Sorry if i wan't clear in my answer, posted that about midnight;)

pathfinding.jpg (349.9 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by dsada · Aug 09, 2014 at 08:44 AM

http://arongranberg.com/astar/docs/graph-updates.php

On this link you can see basic examples of GraphUpdateObject that you need. For example if you just want to put in a new obstacle that you dont want to go through write something like this:

 GraphUpdateObject guo = new GraphUpdateObject(obstacle.bounds);
 guo.modifyWalkability = true;
 guo.setWalkability = false;
 
 Astarpath.active.UpdateGraphs(guo);

This is much more performance friendly than scanning over the whole graph again.

Comment
Add comment · Show 4 · 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 Waldy · Aug 09, 2014 at 10:54 AM 0
Share

Thanks for the reply. I saw that yesterday but i didn't really understand it. So the "GraphUpdateObject" is used to only update the object? Then after you have assigned the new GraphUpdateObject i guess "Astarpath.active.UpdateGraphs(guo);" just tells the grid to update the object and nothing else? I think i might understand it, i'll have a go in a $$anonymous$$ute. $$anonymous$$aybe i was oo tired yesterday or something and that's why i didn't understand it;) Thanks :D

avatar image Waldy · Aug 09, 2014 at 11:09 AM 0
Share

I might as well just post a section of my code as it might help explain a bit easier.

var PathSpawned = Instantiate(StonePath,PathSpawn.transform.position, Quaternion.identity); yield WaitForSeconds(0.5); var PathObj = new GraphUpdateObject(PathSpawned); AstarPath.active.UpdateGraphs(PathObj);

One thing i should say is that i write in Javascript, but it so far A* Pathfinding has worked with it so far. As you can see I Instantiate a stone path on the position of the selection tool, the bit i'm getting a error with is this line "var PathObj = new GraphUpdateObject(PathSpawned);" Where exactly did you get "obstacle.bounds" from? As i tried putting PathSpawned.bounds but it still gave me a error. Would i have to put the script on the path it's self and then do the UpdateGraphs there? Or isn't the variable supposed to be different?

avatar image dsada · Aug 09, 2014 at 12:23 PM 0
Share

Well for example your meshrenderer has bounds or your collider has bouns. So for example

 var PathObj = new GraphUpdateObject(PathSpawned.renderer.bounds);
  
 AstarPath.active.UpdateGraphs(PathObj);

But you can use your collider as well if you have one I just wrote an example.

Dont forget to set those walkability properties that i did because this way you tell nothing to the graph. The nodes are still going to be walkable.

avatar image Waldy · Aug 09, 2014 at 01:20 PM 0
Share

Thanks:D Got it all working and now ins$$anonymous$$d of dropping to about 20 frames per a second it only drops by about 1:D Thanks again for you help, i appreciate it.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How can i stop my game from laging during instantiation? C# 2 Answers

foreach code causes lag spike C# 2 Answers

Mac 10.6.8 lagging with Unity 4.3.2f1 0 Answers

Reduce lag... in Unity Indie? 3 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