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
2
Question by bdickason · Aug 10, 2014 at 02:24 PM · builddebugenvironmentdevelopment build

Using Environment variables (Such as keys to external services)

My game is open source (on Github: https://github.com/bdickason/stormsword) which adds some interesting challenges when working with 'protected' data.

We are trying to implement MixPanel for tracking things like the user's OS, how many times they've loaded the game, etc.

I have a background in web development and would normally set an environment variable on the server which allows different environments (dev, production, per-developer) to have different keys configured and loaded in at run-time.

I would like to avoid storing our MixPanel key in the code, both because I have learned better than doing this, and because I don't want to expose our Mixpanel key publicly in our Github repo.

I've looked into GetEnvioronmentVariable but have not been able to figure out how to get Unity to read from the current environment (for example if I add something to my ~/.profile script it doesn't show up). I also will need to figure out how to make this work on Windows as some of our devs use Windows, some OSX, some Linux.

I also have looked at the PlayerPrefs scripting API but this seems to be used more for player Data.

Any advice would be appreciated!

Comment
Add comment · Show 5
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 mitchmeyer1 · Nov 01, 2016 at 04:07 PM 1
Share

Figure out a solution for this? Im surprised I cant find any support for this

avatar image bdickason mitchmeyer1 · Nov 01, 2016 at 05:58 PM 0
Share

@mitchmeyer1 unfortunately I wasn't able to find a good solution for this and ended up punting on $$anonymous$$ixpanel support. I suspect it's a common problem and I was also surprised to find little to no support/solutions available for this :(

avatar image Glurth · Nov 01, 2016 at 04:31 PM 0
Share

Don't let the name PlayerPrefs through you off: they don't mean "player" as in "player 1", they mean player as in the "Unity program player", or the DVD "player". This is a fine place to store client side configuration information.

avatar image mitchmeyer1 Glurth · Nov 01, 2016 at 04:45 PM 1
Share

I get playerprefs, they are very useful for certain things. But I was asking more about @bdickason's comments concerning Environment variables. $$anonymous$$y app signs in to local API, dev API, and prod API based on if my clients using it vs me making changes locally and testing. Would be great if i could use the dot net GetEnvironmentVariables to see where the instance of the app is running, but my user and process variables come back blank. Only system env vars come back and thats not where i store my api_url variable

to expand on that, i have a staging webgl build and a production webgl build. It would be nice if they could read an env var in their environments and point to the correct APIs based on that

avatar image Glurth mitchmeyer1 · Nov 01, 2016 at 05:01 PM 0
Share

try System.Environment.CurrentDirectory ? Other useful stuff in that class to..maybe that will help? https://msdn.microsoft.com/en-us/library/system.environment(v=vs.110).aspx

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ContractorNation · Jul 23, 2020 at 08:22 PM

 string dosFilePath = @"%USERPROFILE%\Documents\myFile.txt";
 Debug.Log(System.Environment.ExpandEnvironmentVariables(dosFilePath));
 // C:\Users\myUser\Documents\myFile.txt
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Build to WEBGL: Development build will not finish sucessfully 0 Answers

My brand new Galaxy S4 mini is not recognized 1 Answer

Is there a way to see what unity is building as it builds. 0 Answers

Unity build freezing after same number of Debug.Logs 0 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