How to stop Unity & MonoDevelop preventing my Mac from going to sleep ?

Hi, (I’m french, please excuse any mistake).

I have a problem on Mac OS X 11.11.6 and Unity 5.40f3 personal. EDIT: seems to still be the case in 2017.x

When Unity (and MonoDevelop) are running - and doing nothing - they prevent my Mac from going to sleep. I did not find any setting about that.
This is anoying : I have to quit these applications before leaving home to work or going to sleep. I would like to let them running (as for any other app) but electricity is not free and I care about… the planet ?

This is my first ever question on this forum, hope I asked it in the right place. I searched for a similar question but I did not find any.

Thank You.
Cédric.

For those whom would like to check this issue by themselves, here is a screenshot of what is happening on the Mac.
The screenshot is in french, but I put in english explanations.
Thank you for your help.

this is especially annoying if you’re on a macbook and the mac won’t sleep, draining the battery to zero! this has happened to me a couple of times! (sorry this is not an answer, i can’t seem to view or add a comment)

I can confirm that this is still the case in Unity 2017.3 !!!

Please is there any way to turn this off? Because thats the reason why you always have to close unity instead of leaving it open - what is the problem - this is the only program preventing a sleep on mac os…

Im not a MAC user, thank the heavens, but Im quite sure you can simply modify the power settings manually using something like ‘pmset’ to manually set/reset programs that are registered to prevent sleep.

As it appears Unity’s hook on Audio Device is preventing sleep, try clicking “Disable Unity Audio” in Audio Prefs.



https://stackoverflow.com/questions/12790844/macosx-10-8-2-how-to-clear-unwanted-power-management-assertions

Since it is the audio hook that is preventing the computer from going to sleep, one way of doing it is simply to turn off the audio in Unity.

I just tried this, using the Activity Monitor to check as suggested above. Toggling audio in unity (simply by pressing the audio button at the top of the Scene view) changes the “Yes” to “No” in the Activity Monitor’s “Preventing Sleep” column.

Of course, this still requires you to remember to do something when you leave your computer, but something that’s quite easy and considerably less drastic than quitting Unity.


Further investigation suggests that the above is at best an intermittent solution. Please read on for something more reliable…

I have now been experimenting with the pmset stuff that meat5000 posted about. Running pmset -g assertions does indeed show that the audio daemon is preventing both system and display from going to sleep, and that these assertions were created for Unity.

So, the answer seems to be to kill the audio daemon.

To do this, you can run ps -ef | grep coreaudiod in a terminal to get the pid of the daemon process, and then kill -9 <pid> (or sudo kill -9 <pid>) to kill it.

If you watch your Activity Monitor when you do this, you should see the offending “Yes” change to “No”. If you do the ps command again, you’ll see that coreaudiod has restarted, but the pmset command no longer shows those sleep-preventing assertions.

However, as soon as you bring focus back to Unity, it once again tells the audio daemon that it wants to prevent sleep; “No” turns back to “Yes”, and the pmset output shows the assertions again.

So if you want to use this, make sure you do it right before leaving the computer and crucially, without accidentally giving focus back to Unity.

I just tried it here - and it would have been a great solution - but sadly I have always audio muted in the scene view - but the column still shows “preventing sleep: yes” :frowning:

The other work around by killing the process which causes it seems a bit too harsh - I think unity should simply fix the audio device shutting down correctly if someone is turning off the audio at the scene view for example.

Or maybe there is a way to disable audio globally as a “prevent sleep” device in mac?

In iTunes you can see the correct behaviour because as soon as you pause audio the colum changes the state. Just not in unity - something is keeping the audio always on - I also reported an issue already to them - if they publish it in issue tracker we can start upvote it.

Yeah I have written them and they even acknowledged the problem - but it looks like they have ignored it. They said to me even if its telling that the mac doesn’t go to sleep it goes to sleep (!!!??)! Which is a wrong assumption - it is just turning off the monitor but the mac is definitely not going to sleep :frowning:

I guess more people will need to tell them so they finally fix this bad issue. They would just need to turn off all audio devices when idle so that the mac can go to sleep as every other application does.

I submitted a bug for this issue a little while ago and recently got a reply back. I was informed my bug was a duplicate of a known issue and they gave me a link to the item in the issue tracker which can be found here: