A downloadable Unity WebGL Template

Download NowName your own price

Minimal WebGL build template.

Features:

  • Scales canvas to fit the window horizontally + vertically while maintaining aspect ratio (can be disabled)
  • Centers canvas in window
  • Customizable background
  • Basic loading bar (2020.2 and higher only - please comment if you need this added to earlier versions)

To use:

  1. Download and unzip
  2. Copy the "WebGLTemplates" folder into your project's "Assets" folder
  3. File -> Build Settings... -> WebGL -> Player Settings... -> Select the "BetterMinimal" template
  4. (Optional) Customize settings
    • Enter colour in the "Background" field
    • Enter "false" in the "Scale to fit" field to disable scaling
    • Enter "true" in the "Optimize for pixel art" field to use CSS more appropriate for pixel art

Ideal for embedding on sites like itch.io which provide an external full-screen button.

StatusReleased
CategoryTool
Rating
Rated 5.0 out of 5 stars
(63)
AuthorSean
Made withUnity
TagsMeaningful Choices, Unity
Code licenseMIT License
LinksSource code

Download

Download NowName your own price

Click download now to get access to the following files:

Better Minimal WebGL Template v2.2 (for Unity 2020.2 and higher).zip 3 kB
Better Minimal WebGL Template v2.1 (for Unity 2020.1).zip 2 kB
Better Minimal WebGL Template v1.1 (for Unity 2019.x and lower).zip 2 kB

Development log

Comments

Log in with itch.io to leave a comment.

Viewing most recent comments 2 to 41 of 63 · Next page · Last page
(+1)

Thanks so much for this, saves from so much headache... wish I found this before wasting hours of my time though haha

(2 edits)

First of all, Thanks for the Awesome Template. Solve some Rendering issues caused by the auto scalings.

Kinda new to Scripting and totally clueless to WebGL and html editing,

if i wanted to add a Container for the Loading Bar and also a Logo.png on the Loading Screen. Where do i need to inject the code? i've tried copying some sample of other working template but im not getting it to work.

(+1)

The loading bar is implemented by modifying the inline style of the game canvas to apply a gradient background (line reference). If you wanted to put it in a container and show a logo, I'd recommend adding your own HTML elements that are positioned on top of the canvas and changing this so it targets one of them and then removes them after it's fully loaded.

Thanks for the template!

Scale to fit seems to fail again in Unity 2022. Like ThisIsNik, I’m using manual dimensions since auto-detect fails on itch.io (with any Unity template anyway).

But I think I found the reason: itch.io uses a fixed width for the main content column, so resizing the window won’t affect it.

If you change Integration Options to Click to Play in Fullscreen, then it will open the game in a full tab and it will behave as in your demo GIF, resizing the canvas with the window.

I guess that for embedded frames, we should just keep a fixed size…

If you don't want to use the fullscreen by default, but still want users to have the option, itch does have a "fullscreen button" checkbox which should work with this template.

(+1)

Ah, that’s right, I’ll try it!

I got these errors in the console (see screenshot below) immediately after selecting your template. I was using a Windows 11 version 21H2 laptop with Unity version 2020.3.37 LTS version and I downloaded the version 2.2 of your template. I made a video if you want to see it.I don't know how bad leaked allocations are but I thought I would post this comment just in case.

(2 edits)

Hello, is it possible to add percentage number on top of the loading bar? (like "10%", "11%", "12%"...)

I've tried a "ctx" method with that index.html but that didn't work, I guess I'm still not very familiar with JavaScript and html, ha ha.

https://www.w3schools.com/graphics/canvas_text.asp


(Also, thank you very much for making this~)

The canvas that's referenced in the template is managed by Unity to draw the game itself, so I wouldn't recommend using it to draw loading text. What would probably be easier and more accessible is to manually add a separate element to the page (just a div or etc, not a canvas), style it to be placed on top, and update its text in the progress handler (line reference).

(+1)

Oh, yeah that's way easier, touching the canvas just seems to break everything. 😆

I now use a div added with style="position: fixed" with width/height/margin adjustments and is working perfectly.


Thank you very much~

(+1)

Great!

(1 edit)

Hi Sean,

This is working great. How would I add a slight padding to the sides of the game so it doesn't fill up the entire window, but still scales? I tried adding a margin to the game-container div and it only affected the top (I have very little experience with HTML).

(+1)

To add some padding, you could modify the two lines of the template where the window size is retrieved (seen here). Subtracting some fixed amount from this width/height will have the same effect as adding that amount as padding.

(+1)

That worked! Thank you

Is it working in newer versions of Unity? On my side everything turns black when I try to use it.

If it's not working for you, could you share the specific version of unity and of the package that you're using?

I'm experiencing a similar issue with template version 2.2 in Unity version 2020.3.31.f1.

It looks like Unity isn't replacing any of the %UNIY_WIDTH% etc placeholders, leading to syntax errors when parsing the resulting html.

(+1)

Are you sure you downloaded the right version of the template? The placeholder strings in v2.2 are in the format "{{{ VARIABLE }}}" instead of "%VARIABLE%"; the latter is the format from v1.1, so you may have accidentally used that instead.

I just double checked template v2.2 against Unity v2020.3.30f1 locally and it seems to work fine, lmk if you have any other issues.

(+1)

Yes, you're right. I'm not sure how I ended up with an old version. I replaced the files while the editor was open so maybe Unity was running off an in-memory cache rather than the files on disc? Very strange. After replacing with template version 2.2 and verifying the version was correct before launching the editor, it's working much better now. Thank you!

(+1)

Thank you!

(1 edit) (+1)

Elegant solution, thank you!

Deleted 207 days ago

Hey there, I took a look at your itch profile on desktop and the embed you have right now seems to be working fine, with the white loading bar visible. What you may be seeing is that your browser has already cached the files, and may only be sending the progress event for 0 or 100 and skipping most of the loading state on repeated visits.

Deleted 207 days ago

The template isn't actually responsible for any of the progress events, it just listens for the progress from unity. If it's behaving strangely on other browsers, it may be an issue with how unity is loading the files and firing the events.

If you want to force it to go slowly locally just for testing purposes, most browsers have a network tab in their dev tools which allow you to disable caching and simulate slower network speeds.

Deleted 207 days ago
(+1)

Yo are the best dude

(+1)

This is a life saver! Thankyou!

(+1)

Hey, it's not resizing automatically for me when uploading to itch.io. It works perfectly on localhost though. I'm using Unity 2020.3.9f1 DX11 and the template for 2020.2 and higher. My itch.io settings are "embed in page, manually set size (auto-detect size is not working. itch throws error 'No dimensions provided or detected')"

Either way great job on the tool :)

Hey, I tried to reproduce this issue but everything seems to be working fine for me using Unity 2020.3.9f1 and the 2020.2 template. When you say it's not resizing, what's the behaviour you're seeing?

I was able to reproduce the "no dimensions provided or detected" issue, but that appears to be a bug in itch.io itself: the same thing currently happens when using the default unity templates. You may be able to report this to their support for more info.

I mean that the resolution of the game doesn't increase/decrease as you resize the browser window on itch.io, such as in this gif.

Would you be able to share an example of a case where it's not working? It's all working as expected in my tests.

Sure, I'll pm you on twitter.

after importing i can't be able to make the build for webgl and upload it to itch.io

Could you give more details about the issue? What version of unity, what version of the package, any specific error messages, etc?

I've tried to upload it to itch.io and it doesn't scale with the screen size and it becomes fixed and in itch.io if I try automatically detect HTML size then it gives me an error and I am using Unity 2020 3.21

it worked in unity 2019 but not in 2020

Are you using v2.2 of the WebGL template? There are major differences across Unity versions, so if you've copied the version you were using in 2019 (i.e. v1.1) it would not work as expected.

yes i am using unity 2020 3.21 but thanks it worked fine in unituy 2019 i've downgraded my project for this to work

Really love this template Sean - been using it for a while now!
Is there any way you could guide me in how to change the unity logo in the load screen (alternatively adding a background) in 2019.x? I am having trouble figuring this out (haven't quite looked into the background but I do see the update for 2020.)

Unfortunately I think the logo you're talking about is part of the game itself, not the WebGL template, and can only be removed if you pay for a unity license (see here for more info).

(+1)

No worries - thank you. I am trying to incorporate the scaling from your code to work in a different template I have. You found the perfect formula to get it to work. Not quite there yet =P

hi, i just try in unity 2020.3.22 and is work great on mobile but problem is not show loading and logo, can you send me here a script or something to fix this problem?

This template is intended to be minimal and so doesn't include a logo/loading bar. If you'd like to add those, I'd recommend looking at the source for the default template that comes with Unity.

i dont know nothing with html code :) can you please make option in your cool script and update to download please?

A few people have asked for this in the past so I've added this to the 2020.2 template (see here for details).

the loading is good but sadly in mobile is not show full screen on portrait mode, you can play game here to see how it show in your mobile

The template is scaling the game as expected: It's scaling it down such that the whole canvas is visible while maintaining aspect ratio.

If what you're expecting is for it to automatically fullscreen or lock into landscape mode to make better use of the device's screen real estate, that's something which should be handled by code specific to your game or by the site embedding it (e.g. itch has orientation and fullscreen settings on the project page).

Hi. It is totally what I need. How can I set up for images on the loading like background images, logo?

The default template included in Unity (the non-minimal one) includes a loading bar. I'd recommend taking a look at the source for that and copying over the bits you'd like to use.

If you just want a static loading image, you can add an extra line of CSS to give the game a background while it's loading.

hi, i just try in unity 2020.3.22 and is work great on mobile but problem is not show loading and logo, can you send me here a script or something to fix this problem?

Hello, I do have trouble getting it to work with Unity 2020.3.20f1.

I did set the Scale to fit to true but it does not seem to work after the upload on itch (currently still a draft, so I can't provide a link).

Hey there, I tested on 2020.3.23f1, and it seems to be working as expected. Are you sure you used the correct version of the package (v2.2)?

(+1)

Works perfectly on 2020.3 thanks!

Excellent plugin! How would I go about making it non aspect ratio fixed?

If you don't want it to maintain aspect ratio, you could remove the bulk of the `onResize` implementation (seen here) and just use the window size.

god

(+1)

It solved all the size problems of my project at once, thanks a lot!

(+1)

Still works on 2020.3

(+1)

It works in 2020.2.3f1.. thanks for this

Loving this template, thank you so much for providing it!


One issue I'm having, for some reason since I upgraded to Unity 2021.1 the Minimal presets seem to no longer have a loading bar at the beginning and there's no feedback to tell the user that my game is loading in the background, but I am trying to wrap my head around tutorials on how to reimplement a loading bar, or a loading percentage or anything that just says loading, into this template and I'm really struggling - I'm incredibly bad at HTML and CSS.

If anyone has a solution to help with this, that would be amazing.

the default template included in Unity (the non-minimal one) should include a loading bar; taking a look at the source for that would probably be the easiest way to start

Hello, great template by the way, works perfect on desktop and is pretty much compatible on mobile which is awesome, however I'm having an small issue, on chrome and opera mobile browsers I'm getting an aspect ratio distortion on the vertical axis, it looks perfect on firefox.

Thanks in advance for any help with this.

Hi Sean, great work on this, however I am having an issue.

The build works on itch however when I try to host it on GitHub Pages, it causes a 404 error, I think because there is no templateData folder after building. Do you know what can be done to fix this?


Thanks

I don't know why the choice of host would make a difference for this; are you sure you've included all the same files and deployed correctly in both cases? If you're getting a 404, my initial guess would be that the GitHub pages deployment is missing one or more files from the build output.

(+1)

Hi Sean,

looks like it just took a while for the GitHub Pages to set up, its working perfectly now, thanks for the reply.

Will this work on 2020.3? I'm sorry I haven't tried it, but since you parted 2020.2 and 2020.1, I think I might ask first 

I've used it in 2020.3.4f1 without issues; lmk if it's not working for you

(+1)

Okay, thanks!

hello, it doesn’t seem to work with Unity version 2020. I get a black screen when I try to build with it :’)

have you double-checked you're using the correct version of the package for your version of unity? there are different versions for 2020.1 and 2020.2

if you have, can you let me know what specific version of unity you're using?

(+1)

ohhhh! Thank you! That fixed it :D

(+1)

Thank you for making this, I spent way too much time trying to get this to work and you have even more customizable than I ended up with!

(+1)

Works for mobile!

Five Stars! Beautifully simple to add and build. 

(+1)

Thank you!!

I'm not sure, but I think this gets rid of the loading screen as well? Any way to re-enable it?

there's info on how you can add a loading indicator at the bottom of the page here (you can also use the built-in unity template with a loading bar as a reference)

(+1)

Dude, THANK YOU ! This simplifies my workflow by A LOT !! I'm donating a few bucks.

I seem to be struggling. I followed the steps and when I uploaded my zip to itch.io I get this error in itch "No dimensions provided or detected"

I have the embed in page option selected. When I change it to click to launch in fullscreen the game works but the scaling doesn't work on mobile. 


Any tips or am i missing something? :) 

what version are you using?

(+1)

OMG thanks it just saved my life ahah

(+1)

Thank you so much!

(+1)

Great stuff :) Using this, thanks. 

Deleted 1 year ago

hey there, I tried to reproduce this using the latest version (v2.2 + Unity v2020.2.0b13), but it seemed to work fine. without more info to debug with, i'd suggest trying to use one of the default templates and see if the problem persists as a way to narrow down whether it's actually a bug with the template or with something else

Deleted 1 year ago
Viewing most recent comments 2 to 41 of 63 · Next page · Last page