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
1
Question by lhk · Oct 31, 2010 at 04:37 PM · performancearchitecturemultithreading

Optimize for multicore systems

Hi,

I'm using a computer with an AMD 6 core CPU. When I spawn a huge amount of enemies the framerate drops till the game is unplayable. However using Core Temp I can see that only 1 core is stressed. The other cores are at about 5% load. So here come my questions:

  1. Does Unity support multicore systems ?
  2. If it does, how can I use more than one core ?

I already thought about using more than one thread in my script. The only problem is, that I don't need more than one thread.

  1. Do you need more than one thread ?
  2. Are there game architectures that support Unity with its "internal" multithreading ? I guess that many small scripts may be superior to one big script.

Any advice would be appreciated.

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

4 Replies

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

Answer by StephanK · Oct 31, 2010 at 05:19 PM

As Eric already said you'd have to use System.Threading yourself, but you can't call Unity functions from a separate thread. However if you are experiencing frame drops those might be caused by graphics rather than your own scripts. If you have unity pro you can check the profiler to see what's causing your framerate to drop. If you don't have pro you could still take a look at the Stats in the game view. If you are using lots of draw calls your fps drop is probably caused by rendering rather than your scripts. If that's the case you should think about how you could optimise render performance.

If scripts are causing the problem you should think about how to optimise those scripts. Debug.Log will slow down everything for example. If your code is already optimized you could also think about how often your enemies need to update. Maybe you are still fine when those enemies only update every other frame?

Comment
Add comment · Show 2 · 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 lhk · Oct 31, 2010 at 05:51 PM 0
Share

The idea not to let the enemies update every frame is great. I will try to implement this.

avatar image lhk · Nov 01, 2010 at 04:51 PM 0
Share

Now the enemies don't update everytime. Works great.

avatar image
1

Answer by Eric5h5 · Oct 31, 2010 at 05:03 PM

Many small scripts won't run any differently than one big script as far as CPU usage goes. In order to use threads, you need to explicitly use System.Threading in your scripts. Note that no Unity functions are thread-safe; only Mono functions can be used in such a way. (Unity 2.6 will randomly crash if you attempt otherwise; Unity 3 simply won't run attempts at threaded Unity functions, though it doesn't give you any error messages.) The Unity engine itself has a certain amount of multi-threading, such as physics and mesh skinning.

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 lhk · Oct 31, 2010 at 05:54 PM 0
Share

The problem is, that I don't need threads. The AI script is very simple and controls the movement as well. Thus I need the Unity functions. Why aren't many scripts useful for multithreading ? I've got about 50 - 500 enemies and each has its own script. One should think that each core could handle 100 enemies and everything would be fine.

avatar image Eric5h5 · Oct 31, 2010 at 06:12 PM 0
Share

As I mentioned, Unity functions can't be multithreaded. It doesn't matter how many scripts you have: they all run as a single thread, in linear order. Potentially you can offload AI calculations in separate threads, as long as anything that touches Unity-specific functions runs in the main thread.

avatar image lhk · Nov 01, 2010 at 04:51 PM 0
Share

Hm. I'm sort of disappointed of Unity3d

avatar image Eric5h5 · Nov 01, 2010 at 05:29 PM 0
Share

@lhk, you're welcome to try finding engines that are significantly more multi-core usable for scripting. Game program$$anonymous$$g typically does not lend itself to such a thing.

avatar image
1

Answer by Ryan 2.du · Nov 08, 2010 at 02:13 PM

Having been an engine programmer and a game designer, I'd love to have some way of parallelizing parts of my game.

While I agree that general game logic is difficulty to parallelize, I wouldn't mind some options without having to go all the way to building my own job system. Given your company's awesome cross-compiling expertise, I would think there'd be some people already experimenting with this.

For example:

i) Some built-in parallel options :

  • Deferred ray casts (These would be available next frame so they could be batched and parallelized)
  • Deferred API physics calls
  • Etc

ii) or a even better, a more general deferred batching system

  • example: foreach (input, output, function, when)
  • if we were able to tag functions with no side effects, you could even cross compile to SSE or the like.

Great Software! Thanks!

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
1

Answer by AntonioT · Nov 08, 2010 at 04:03 PM

The ability to parallelise scripts is certainly something that we would not only benefit from hugely, but also, something that we would be losing out on severely if we do not have it.

It's not just about multi-threading and assigning jobs to new threads etc. What about having single tasks that you want spread over multiple cores so that they all share the load and not just one is stressed ? Multithreading and parallelising are both important I would say.

Multi core cpus are a reality here and now and we lose performance not using them to their fullest.

Another thing would be to allow control over the degree of parallelism so that tasks can be told "use as many cores as you can but no more than 2 or 4 for instance".

Especially graphic intensive scripts would see massive performance boosts if they could spread the load and have more instructions executed in parallel.

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

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

1 Person is following this question.

avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Is there a way to use SkinnedMeshRenderer.BakeMesh() in multiple threads? (Mesh Instancing) 0 Answers

Setting positions of cubes directly without using transform 1 Answer

Why is ECS better than actual Unity Entity-Component pattern ? 1 Answer

How to make game use dual core or duo core by Unity3D? 2 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