Get current username

Hi, i’m trying to get the current username on Windows and Mac.

For Mac i found Environment.UserName but it returned NULL

Can anyone help me to do this on windows and Mac using Javascript code?

Thanks.

Environment.Username is the appropriate call, it works perfectly fine for me inside the editor.

I’m making an assumption here, but have you made sure you included the import System; at the top of your javascript file?

The current user can mean many things. If you just want the profile logged into the device,

string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

This gets the user the game is running as, which is safer than Environment.Username.

If your game is using OAuth or its own internal login system, then that won’t work.

Yes, i did. i don’t know why it throws NULL but i already solved it. Thanks :wink:

If anyone has this problem here’s the solution.

System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) returns the current username on Windows and Mac