- Home /
Can Unity webGL run on server side?How could i manage to do that?
I am new to WebGL and I would like to do this: I have in Unity a cube gameObject rotating around y axis and a UI text gameObject counting how many full 360 turns the cube did. The cube does a full 360 turn in 1 minute. That is done, it is not a problem. I would like to make a webGL build and start the webGL app on a server just right now. I wait 30 minutes and i vist the url in which i started the webGL app. I want to see 30 in the text field of the ui text gameObject. So time is running on the server and every time i see that web i can see the actual moment of that time flow. Questions: - Can this be done using Unity webGL build? - If so...What is the eaiest way to manage this? What unity tools or services do i need? - Could i do this uing a free server service? Could somebody point me in the right direction? Thanks a lot
some webgl result like this? https://youtu.be/82_-a7WF3vs It's a WebGL Live Strea$$anonymous$$g demo via F$$anonymous$$ WebSocket plugin.
Answer by Bunny83 · Nov 03, 2019 at 01:34 PM
What you have described sounds a bit confusing. First of all WebGL is just a rendering solution in web browsers. They always run on the client side. Of course a WebGL build is usually hosted on a server where users can actually connect to and load that page in their browser.
Some things which are not clear and which we can not answer here since they do not belong here:
It's not clear if you want to have one server based time for all users which connect to your server or if you want to have a seperate "time" for each user.
If each user should have a seperate time it gets a bit complicated since you need some sort of user management on your server. At the same time, depending on where you live, you might get into trouble with personal data and privacy.
For doing serverside logic you usually implement your logic directly on the server (using PHP or another server-side scripting solution) and have your WebGL build communicate with those through UnityWebRequests.
We can not suggest hosting solutions for you since this would be a subjective answer and such questions / answers do not belong here since they will never be "answered". Also hosting solutions can differ heavily depending on your requirements and your location.
Note that depending on what your actual goal is you might not need serverside logic at all. You can store a timestamp in a cookie on the client side so when he loads the page again you can figure out on the client side how much time has passed. Of course this would only work if every client should have their own seperate time. If you want all clients to see the same time it has to be server-side. Also If you want to support that users can "log-in" from other locations / devices you also need a server-side solution and some kind of user accounts on your server.
Such topics are a bit too advanced to give a full example as an answer here. Besides that there are many different ways how one could accomplish such a system. Also since the actual usecase is not clear it's difficult to give a clear answer to your question.
Answer by dbr3d · Nov 03, 2019 at 04:11 PM
Thanks a lot for your answer @Bunny83 . I would like to add some info after reading your post. I would like to have the same flow time for all the users who conect to the server so i believe i will need server side logic, as you nicely said. I believe now that server logic can´t be a unity webgl build , but could server logic be done with unity? it should be a unity build uploaded to a server? And the last point about this problem...Could this be done without login in the client side? I mean i just type the url in which is uploaded the client as a unity webgl build, that client communicate with the server side through UnityWebRequests and i see the 3d world with the word rotating and the UI text showing number 31. In other words is it possible to conect with this 3D world in which the cube is rotating without log in any account? Thanks for your attention.
Your answer
Follow this Question
Related Questions
My WEBGL game is encountering issues with CORS but not other games? 2 Answers
WebGL Build throws a 404 Not Found error for UnityLoader.js on the server, what am I doing wrong? 1 Answer
Is there anyway to use WebGl on a website without having users install a plugin? 0 Answers
WebGL -Chrome seems to do nothing while loading WebGL appllication 0 Answers
webgl rotate texture on the face of cube using glmatrix 0 Answers