Can Unity create browser based games?

Hi there.

I didn’t find a clear answer, so i want to confirm this -

Can I create browser-based (html/js/canvas/webgl) games with Unity?

If so, where can I find docs?

https://learn.unity.com/tutorial/how-to-publish-for-webgl

2 Likes

The answer is yes, very well, and performant. Your base will be WebGL. Which you can code scripts in JS/WebGL/etc. Unity is very forgiving, and there are plenty of Unity Docs that cover this, and (youtube) video tutorials, to set you on your path…

1 Like

Has things really changed that much on the WebGL front? Last time I checked (2 years ago), it was a bad unsupported mess that was nowhere near the capabilities of the Unity browser plugin.

5 Likes

Well, it is possible to make even AR application in webgl using 3rd party framework and have that work on mobile. Though you’ll be seeing “Mobile WebGL not supported” warning, which you can disable.

Even 5 years ago there were demos using WebGL on Ludum Dare, made with Unity.

That it’s possible doesn’t mean it is well supported and performant.

I tried to do something like an interactive blog post with Unity in WebGL a while ago (and it was actually 1 year ago) and I found the experience so bad and lacking I abandoned it in frustration, since a lot of things weren’t working properly and even when I go them to work, they performed like ass (and I’m not talking about mobile devices here).

I don’t have previous experience with WebGL. I do have experience with the old Unity plugin, and it was leaps and bounds better than this (most things just worked, and performance was pretty good). Maybe it’s unreasonable to expect a similar experience in WebGL (does webgl just straight up suck?), but even then, I do feel like Unity’s WebGL implementation is super half assed.

Which is why I’m genuinely asking if things changed on the WebGL front recently, since from my experience instead of the “The answer is yes, very well, and performant.” my answer would be “Yes, barely and it’s really slow, look at Playcanvas instead”.

To know “whether things improved” it is necessary to know in what state they were before. And I haven’t tested it 1 year ago.

The scenario I dealt with involved running face detection every frame in webgl while displaying camera feed. It worked fairly well. That’s all I know. Not C++ level performance, of course, but it felt like it was decent enough.

shrug it works just fine

You can using WebGL, yes. But the real question is if you should.

If you don’t have any Unity experience and are looking for an easy way to create a browsergame, run away and choose a different solution. As indicated before in this thread, Unity WebGL had/has some serious issues and limitations. Here are a few I’ve had to deal with in the past:

  • No proper mobile phone support
  • Long compilation times with no proper way to test JS functions without building the game
  • Slow runtime/high system requirements
  • No builtin networking, requiring you to manually implement websockets in JS and call them from C#
  • Big build sizes, making loading really slow on bad connections

The only real use I see for Unity WebGL are simple demos you want to share quickly. For purely browser-based games there are many much better solutions out there, especially if you don’t need 3d.

Do someone has current up to date experiences?

We are using WebGL for interactive experiences(think of expo style events). And it performs quite well but there are couple of things we had to do and things to be aware of.

Had to write custom shaders due to standard ones taking insane amount of performance out. Doing this allowed our projects to run on mobile without much of the issue.

The amount of memory you get is quite small… If you run out it crashes and tab reloads. For this we have to unload the scene first and then load a new one. It makes it a bit more difficult for us cause we are using full set of textures for each mesh(albedo, metallic, normal, sometimes emission too). Playing around with compression helps a bit.