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
4
Question by Joshua Mitchell · Mar 05, 2010 at 03:26 PM · variableurl

How can you send variables to unity3d from the url?

Need to send variables in to unity3d from url.

Example: www.domain.com?varname=4

Then have access to varname in unity3d like a global variable.

thanks,

Comment
Add comment
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

6 Replies

· Add your reply
  • Sort: 
avatar image
6

Answer by Cyclops · Mar 05, 2010 at 06:05 PM

I'm not a network guru, but I think this might work. It would be a two-step process, the first, where your web-server software (for example, Django) breaks down the URL and gets the parameters from the URL.

Second, your Browser can communicate with the Unity executable through the SendMessage() function. This allows the Browser to pass information to Unity (and vice versa). So you would SendMessage(parameter) to pass it to Unity.

The SendMessage() page has a lot more information, including sample code and HTML, that should help you.

Update: just ran across a similar question here in Answers, with a very nice solution: Extract Arguments from URL. Basically, he suggests to use the Application.absoluteURL, which allows your Unity application to see the entire path string it was called from. Then you would just have to parse that string to get the variable.

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
avatar image
1

Answer by alph · Apr 13, 2011 at 11:11 AM

I'd like to add my 5 cent to this, as I couldn't find any relevant example code to do exactly what I wanted to do.

Using Unity3D v.3.3 and building for webplayer, unity will make a ready WebPlayer.html file for you that embed your .unity file and everything works off the bat. To get url parameters from this setup using PHP do this:

  • copy WebPlayer.html to WebPlayer.php and open in your favorite editor
  • add this line to the very top of the php file:

<? $arg = $_GET["arg"] ? "?" . $_GET["arg"] : null; ?>

  • about line 15/16 find this code:

unityObject.embedUnity("unityPlayer", "WebPlayer.unity3d", 680, 600);

  • replace "WebPlayer.unity3d" with this:

"WebPlayer.unity3d<? echo $arg ?>"

  • in the url, call your game with something like this: http://myServer.com/pathToGame/WebPlayer.php?arg=myArg1,myArg2,myArg3...

  • now in unity:

string raw = Application.srcValue;
string[] tmp = raw.Split('?');
string myArguments = tmp[1]; // will give you "myArg1,myArg2,myArg3..."
// ..further parse myArgument as you like

This can probably be done in different ways, don't hesitate to comment some improvements..

Comment
Add comment · Show 2 · 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
avatar image ABerlemont · Apr 21, 2015 at 03:38 PM 0
Share

Great "workaround" Using u5 and Application.srcValue stops at the unity3d file path. I'm using Application.absolutePath ins$$anonymous$$d.

avatar image Ricna · Jan 12, 2016 at 06:24 PM 0
Share

I had used this same way for my applications, but now I need to build the same app for WebGL. I'm trying to find a way without success until now. The application don't receive the params from URL but from a query in databases using the PHP. You know how to get the parameters in this case? Thanks!

avatar image
-2

Answer by Minato Namikaze · Mar 06, 2010 at 07:45 AM

Importing assets is simply done as dragging and dropping them onto the Unity window.

EDIT: Sorry, I didn't realize you meant receiving variables from websites. Disregard my post.

Comment
Add comment · Show 1 · 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
avatar image Motionreactor · Mar 09, 2010 at 05:25 AM 0
Share

You missed the point of the question. The question refers to runtime data acquisition, not editor asset importing.

avatar image
-5

Answer by Minato Namikaze · Mar 12, 2010 at 07:39 AM

Re-post, sorry about that.

Comment
Add comment · Show 1 · 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
avatar image SrBilyon · May 29, 2011 at 04:40 AM 0
Share

It all good bro. :)

avatar image
0

Answer by ArunRaj · Aug 17, 2011 at 06:25 AM

thank it helped me a lot :)

when passing two arguments , follow this

and follow the same steps !!

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
  • 1
  • 2
  • ›

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Hide public field on base class but show it on derived class 1 Answer

How to properly declare this variable 2 Answers

How do you clear a variable in the inspector? 4 Answers

variable doesn't change 1 Answer

Why the variable updates only twice? 1 Answer


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