Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by lweller2020 · Jul 11, 2017 at 07:58 PM · stringapplicationapplication.openurl

Unity C# Application.OpenURL not working with variable input

Also posted on Stack Overflow at: https://stackoverflow.com/questions/45039888/unity-c-sharp-application-openurl-not-working-with-variable-input

I'm building an application in Unity and I have a button that uses Application.OpenURL() to bring the user to a certain page when clicked. Up until now, I was using the fully typed out url name in double quotes as the parameter for the OpenURL function, and it was working as I intended. When I pressed the button the page was opened in the browser.

In order to incorporate multiple possible urls, I have changed the parameter to a string variable called url_name. Since this change, nothing happens when the same button is pressed. My code currently looks like this:

 IEnumerator alertPopUp(string metaData_Content){

     if (alertDelay)
     {
         yield return new WaitForSeconds (alertDelayLength);
     }

     string[] tokens = metaData_Content.Split (',');
     string sign_name = tokens [0];
     string url_name = tokens [1];

     string template = "You discovered {0}";
     string data = sign_name;
     string message = string.Format(template, data);


     MNPopup popup = new MNPopup ("Honorary Chicago", message);
     popup.AddAction ("Find out more!", () => {Application.OpenURL(url_name);});
     popup.AddAction ("Not now", () => {Debug.Log("action 2 action callback");});
     popup.AddDismissListener (() => {Debug.Log("dismiss listener");});
     popup.Show ();
 }

Notes:

The block that starts with MNPopup takes advantage of a plugin I got from the asset store that builds formatted pop ups. I don't believe it has anything to do with the problem, especially since the script worked as intended when I had a string typed out. I have tried testing with Debug.Log(url_name) in place of Application.OpenURL(). The log displayed the correct url as intended, so it appears that url_name is the value I intend it to be.

Question:

Why is the Application.OpenURL() function working when I type out a string, yet not working when a string variable is inputted?

Comment
Add comment · Show 13
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 Jinkata · Jul 11, 2017 at 08:29 PM 1
Share

have you tried Debug.Log(url_name); to make sure that what's stored there is correct? Perhaps it's improperly formatted. I like to put * in the debug Debug.Log("*" + url_name + "*");before and after the variable to see if there's any whitespace.

avatar image lweller2020 Jinkata · Jul 11, 2017 at 09:07 PM 1
Share

I did try Debug.Log(url_name); and it seemed to be the right content. I'll try the asterisk formatted idea now.

avatar image lweller2020 Jinkata · Jul 11, 2017 at 09:11 PM 1
Share

Debug.Log("*" + url_name + "*"); returned *https://stackoverflow.com/users/6706357/luke*. That url looks correct. Any other ideas?

avatar image Jinkata lweller2020 · Jul 11, 2017 at 09:42 PM 0
Share

Where are you setting the metadata? Is this in a file that you're loading?

Show more comments
Show more comments
avatar image Bunny83 · Jul 13, 2017 at 12:51 AM 1
Share

There might be non printable characters in your string which may cause problems. Try printing the Length of the string and maybe print the string as hex with that helper:

 public static string StrToHex(string aStr)
 {
     var data = System.Text.Encoding.ASCII.GetBytes(aStr);
     var sb = new System.Text.StringBuilder();
     foreach (var b in data)
         sb.Append(b.ToString("X2")).Append(" ");
     return sb.ToString();
 }

So just do:

 Debug.Log("Length: " + url_name.Length + "\n>" + url_name + "<\n"+ StrToHex(url_name));

Copy the result and post it as comment.

avatar image lweller2020 Bunny83 · Jul 13, 2017 at 04:17 PM 0
Share

The result:

 Length: 47
 >https://stackoverflow.com/users/6706357/luke
 <
 3F 68 74 74 70 73 3A 2F 2F 73 74 61 63 6B 6F 76 65 72 66 6C 6F 77 2E 63 6F 6D 2F 75 73 65 72 73 2F 36 37 30 36 33 35 37 2F 6C 75 6B 65 3F 0A 

0 Replies

· Add your reply
  • Sort: 

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

69 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading level using a string created through code. 3 Answers

PlayerPrefs from One App to Another. 1 Answer

Open Url in browser on button click 1 Answer

Using Application.OpenUrl to open a URL in a String variable 1 Answer

Extend from box. Notes 2 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