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 Wisearn · May 17, 2016 at 01:19 PM · javascriptwebglnodejsnode

What is unity WebGL export's correlation to Node.js?

Hello world!

We're trying to play around with unity's webgl export and for reasons of running our client on certain platforms we already have in place I'd like to find out more about why there are so many references to node in our webgl build.

We're trying to get it to run on node but so far there are so many checks where it tries to find out whether it's a browser or node, it gives me the impression that there's a correct way to run it on node (maybe unity tech devs do it for debug purposes).

So far we're just trying to hack around the checks but if anyone here has any info on this that would be lovely.

Comment
Add comment · Show 2
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 Wisearn · May 17, 2016 at 03:21 PM 0
Share

We found a variable called ENVIRON$$anonymous$$ENT_IS_NODE anyone know what this is responsible for?

avatar image Miiirage · May 17, 2016 at 03:23 PM 0
Share

We are also looking into this, getting stuck with the Filesystem (loading data). The development build seems to point to Node in many ways, while still "expecting" navigator or windows objects. What's the best way to take a WebGL export for Node (to use code for a backend server)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alexsuvorov · Jan 16, 2017 at 12:44 PM

Hello @Wisearn.

It is indeed possible to run WebGL build in node.js (as well as in other shells). However, it would require some manual adjustments, because even though most of the Emscripten code is ready for node.js, some JavaScript plugins developed for browsers have not been fully tested in shells, so, depending on the Emscripten and Unity version, you might get exceptions when, for example, window object methods are used in plugin code, because those are not available in node.js.

So basically there are two possibilities:
a) you can patch all the build code and plugins to make it compatible with node.js
b) you can define a window object as this and override some of its methods (i.e. navigator, XMLHttpRequest etc.) prior to loading your build, so that when you start your build, it will think that it is running in a real browser, and not in the shell.

The second approach seems to be much more universal to me, because:
- you don't need to patch the build code
- you only have to implement such a wrapper once and it will work for future versions of Unity
- you can use the same approach to run your build in other shells.

Still, there is one problem that would be a bit complicated to solve. It is the canvas context functionality (used in gl functions), which does not exist in node.js. Even though there is a working example of a headless canvas in Emscripten code, it is not functional enough to cover all the Unity calls (unless you spend some time to make it work). However, if you just want to test your code in a shell, you can try to create a Development build, which should use a native NullGfxDevice when WebGL context is not available. To check if this functionality is available in your build, disable WebGL in your browser settings and try to run your build. If it runs well with a black screen, then NullGfxDevice code is included in your build and it should also run well in a shell without additional adjustments (otherwise it should print "Could not initialize WebGL context. Failed starting Unity." in the console).

Final solution might also depend on your Unity version (due to usage of different JavaScript plugins). I believe you can do this most efficiently in Unity 5.6, because its loader is independent from the build, so it should be sufficient to just override some of the loader methods to make it load any 5.6 Development build. If you are ok with those limitations, I can prepare a working node.js example.

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

66 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

Related Questions

Can't connect to Web socket, connection refused Unity WebGL 0 Answers

Unity Button as HTML Button 1 Answer

WebGL builds: decipher jsStackTrace errors with symbol map? 1 Answer

Browser interaction to Unity 0 Answers

Unity WebGL Problem 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