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 Weev · Mar 27, 2012 at 02:41 AM · airtsbehave

Scaling AI for Many Actors/Agents

I'm creating an RTS-style game, and while I have AI set up for my actors (turrets, tanks, etc) that works fine, it doesn't scale well. Once a few dozen actors are present, my game starts to slow way down.

I need some guidance on how to design my AI so it scales well. What are some techniques I can use to reduce the workload?

I'm currently using Behave's behavior trees to handle the AI. Is there anything I should be aware of when using Behave for an RTS-style game with many agents?

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

· Add your reply
  • Sort: 
avatar image
2

Answer by senad · Mar 27, 2012 at 09:17 AM

I do not have links, but here are a few thoughts that come to mind:

If you have a general slowdown you might try to reduce update rates. Reducing it from say 200ms to 500ms might not be noticable in the game but double your performance. It might even look more natural if the actors take some time to think.

If you have a lot of actors you might experience performance peeks or stuttering if you have a lot of BT updates in one frame. For this you might want to cap the number of updates which are allowed in one frame.

Another idea might be to move the AI to a separate thread altogether. You will have to spend some work on synchronization and it is a tricky task however.

Code optimization might help you if your AI code has poor performance. Profiling will help you find the bottlenecks.

I hope this helps. Good luck, happy coding. :) :)

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 Weev · Mar 28, 2012 at 03:03 AM 0
Share

Thanks senad. I'm using the indie version of Unity, so the profiler is unfortunately unavailable (I really need to save up for it). I double-checked my update rates for the behavior trees, and it turns out they were running twice as often as I thought, which was a major problem. I hadn't considered limiting the number of updates per frame, and I don't know if it's easy (or possible) with Behave, but it's an excellent piece of advice.

avatar image senad · Mar 30, 2012 at 08:16 AM 0
Share

Hey $$anonymous$$, glad I could be helpful. :)

There is a GUI field for the update rate in Behave, you still have to use it in the code yourself. But it is relatively easy to do so. I found most of the infos in the Behave forum thread very useful: http://forum.unity3d.com/threads/61849-AI-Behaviour-trees-in-Unity-Behave-1.1-released

Also the videos from angry ant.

For the profiling, since unity is using .NET, I think it should be possible to use any .NET profiler out there. I have not tried this though. There are many free and commercial profilers available. The one I have been using at work is ANTS, it has a 14 days trial period which should be enough to profile your AI. :)

avatar image senad · Mar 30, 2012 at 08:24 AM 0
Share

This is how implement the behaviour tree update to use a frequency set in the GUI. You can also have different frequencies for different actors, making some important ones faster thinkers: // Update is called once per frame

void Update () {

 m_timeSinceLastTick += Time.deltaTime;
 
 float frequency = m_tree.Frequency;
 if ( frequency != 0 && m_timeSinceLastTick > 1f / frequency ) {
     m_tree.Tick();
     m_timeSinceLastTick = 0;
 }

}

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to make 2 groups of agents attack eachother? 0 Answers

Using Behave to alert other AI 1 Answer

Tutorials for AngryAnt's Behave 1 Answer

More than 20 instances of a certain script cause fps to skyrocket, is there something I'm doing wrong here? 0 Answers

how to make AI move to target positions 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