Debug OS X Standalone Unity Player

I'd like to debug an OSX Unity Standalone player to capture something that happens at startup.  I know I can attach to a running instance easy enough but I'm not sure for OS X how to start the process.  Would it be .NET Executable?  If so what EXE Path / Program Arguments?  Or is it not possible now?

5 comments
Comment actions Permalink

You should be able to use the Run → Attach to Unity Player menu item to find, list and attach to players available on the network.

0
Comment actions Permalink

Which I said in my post, " I know I can attach to a running instance easy enough"  The issue however is that I need to debug something that happens within the first frame of startup.  By the time that I select the player the opportunity has past.  I need to be able to start the process from Rider and have the breakpoint fire in that first frame.

0
Comment actions Permalink

Ah, I thought that comment was referring to being able to attach to regular .NET applications, not just Unity players. I'm not sure this is possible, to be honest, because it all depends on how Unity initialises Mono, and when Rider can attach the debugger. The only thing to do is try - you'll need to find out what the usual command line args are that you use to launch the standalone player. Then try and put that into a .NET Executable run/debug configuration, and make sure the "Use Mono runtime" option is checked.

This might not work, as the .NET Executable config with Mono might try to invoke Mono for you, rather than just calling the executable directly.

If that's the case, maybe it's possible to specify the debugging ports for the player as command line arguments or environment variables, in which case you could use the "Mono remote" configuration on a specific port, check the "listen for incoming connections" and then launch the standalone player yourself. However, I don't know of any such command line arguments or environment variables - that would be a question to ask in the Unity community.

0
Comment actions Permalink

I've also just discovered the UNITY_GIVE_CHANCE_TO_ATTACH_DEBUGGER environment variable. If you set this to 1 before launching your standalone player, the player should show a dialog box that will allow you to attach the debugger using the existing "attach to Unity process" menu item.

0
Comment actions Permalink

Thanks, when on either of the windows though Rider does not see the standalone build as a unity process in 2017.3 on OSX.  Looking at lsof I see that the standalone does have 2 high ports open for listening at that time, and once the standalone is fully running one of those two is the debug port.  Were you able to see a standalone mode and attach like that?  I know that I can attach manually but it seems like it may be 50/50 if I get the port right.  Is there any way to determine which port to use?

0

Please sign in to leave a comment.