Been developing an application which uses both Silverlight and Unity side-by-side in the web browser. However, we've found that when Unity is performing a lot of work (either due to complex scenes, underpowered hardware, etc) it was negatively impacting the performance of Silverlight to the point of no longer being usable.
We tried having Unity "idle" when not being directly interacted with by the user by dropping its frame rate using Application.targetFrameRate. Initially, it works great and the Silverlight performance shoots back up through the roof. However, the performance degrades to the point where Silverlight starts running at the same framerate as Unity. It also seems to affect the browser overall (closing the window, interacting with it can become delayed).
I've profiled the processing of Silverlight, and considering the browser slowdown, I think the main browser process might not be triggering the main Silverlight runtime's loop. Once the loop executes, the code processes as quickly as ever, but the browser/runtime just waits and waits until Unity runs its update for its next frame. As soon as we set the Application.targetFrameRate back up to 60fps, everything works fine again (albeit with the degraded performance we were trying to solve in the first place)
I put together a sample test that demonstrates this. Simply on the left-hand side in Silverlight, a smiley face follows the mouse cursor and on the right-hand side Unity displays a spinning cube. If you click the "Drop Frame Rate to 2 FPS" button in Unity, then continually move your mouse around in Silverlight, after about 10 seconds or so, you'll notice that the smiley face starts pausing instead of smoothly following your mouse. The performance continues to degrade until the smiley face updates are synchronized with Unity's frame rate (and even worse sometimes if it skips a frame). Click the "Increase Frame Rate to 60 FPS" will fix the performance, and clicking the 2 FPS button after will go through the same process of slowly degrading performance.
You can access the test here: http://sketcher.genexissystems.com/UnityFrameTest/
The only Silverlight code is:
MouseMove += MainPage_MouseMove;
private void MainPage_MouseMove(object sender, MouseEventArgs e)
var position = e.GetPosition(this);
this.image1.Margin = new Thickness(position.X - image1.Width / 2, position.Y - image1.Height / 2, 0, 0);
And on Unity's side, the only pertinent code is:
public class ChangeFrameRate : MonoBehaviour
private void Start()
QualitySettings.vSyncCount = 0;
Application.runInBackground = true;
private void OnGUI()
if (GUI.Button(new Rect(0, 0, 250, 20), "Drop Frame Rate to 2 FPS"))
Application.targetFrameRate = 2;
if (GUI.Button(new Rect(0, 30, 250, 20), "Increase Frame Rate to 60 FPS"))
Application.targetFrameRate = 60;
So far we've tested and duplicated the slowdown on Windows XP and Windows 7 running on IE 8/9, Firefox 13/14, and Google Chrome 17/20. We've also found that the time needed to exhibit the slowdown can vary from operating system and browser though we have found that generally, Chrome takes the longest to slowdown and IE degrades the fastest.
This is created with Unity Pro 3.5.2f2.
Any thoughts or insights on this, or possible solutions would be greatly appreciated! Thank you!
EDIT: By the way, CPU usage during the tests never rose above 2% so this isn't an issue with one of them hogging the CPU, just thread waiting I guess.
FYI doesn't happen on my Mac running Chrome.
@whydoidoit thanks for the mac test; good to hear!
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
5 People are following this question.
Parenting Weapon to Empty = Framerate drops to 2fps
Slower Performance In Web Player Than Editor
Unity performance issues in my scene.
Editor playback performance on Windows