So, I’m trying to make a button BE an image, a .png to be exact. I’m placing that on the Canvas Renderer that automatically shows up when you create a button, but the image is not showing up in game view. When I place that image on the button with a Sprite Renderer it shows up in game view but, I don’t know that will still be clickable button when it comes to game time.
This button I’m creating is nested at the bottom of the screen and when clicked will spawn a unit on the battlefield. I’m a rookie at Unity so any help would be appreciated!
It’s too late for you. But it was the first result when I googled the issue. So I’m writing this for everyone that has the same issue. Select your canvas, go to the canvas component > Render Mode. Change it to “Screen space - camera” and add your main camera to the section below that.
Now try to find your buttons somewhere on the screen (Select the button from the hierarchy and Press F) and even if it didn’t work (it will!), go to the game view and play with the scale and position of your button until you can see it. There is also a possibility that the button is in the back layer. You can change the order of let’s say your background, when you select it (Sprite renderer > Additional settings > Order in Layer)
Hope it helps!
When you create the button component, it has an image already part of the button. Just put whatever PNG file you want into that, and the button should be displaying your image, with the text component overlaying it.
As long as that button is within the viewable range of the camera, I can’t think of any reason it wouldn’t show up in the game view.
Hi, me too… I built my game and couldn’t see the buttons when running it, tried to change the canvas to world space or camera or the default one… nothing !! then as I went to build it for the 5th time, I look over the scenes to include, and I realized the Sample Scene was checked, sure I did some scenery and some script and gameplay content before saving Scene1, but there were no buttons in the sample scene, that’s why they wouldn’t show…felt like a blooper scene myself…
easy fix as you can imagine. just unchecked that the sample scene was to be built too.
I just had a similar issue, but with a peculiar cause that may escape some people.
Let’s say you’ve a complex game and you need to load more than one scene simultaneously, but you want the secondary screen you load to use a canvas set to World Space or Screen Space (Camera) mode. If you put a camera in your secondary scene, Unity will complain when you try and load it because there are two cameras. So you delete or disable the camera from your secondary scene, now what? Suddenly a lot of the stuff on the Canvas doesn’t appear.
That’s because canvas won’t automatically inherit the main camera from your main scene. It’s got no camera, so a lot of stuff simply won’t render! A simple solution is to put this into any object appearing in that scene:
public void Awake() {
var allCanvases = GameObject.FindObjectsByType<Canvas>(FindObjectsInactive.Include, FindObjectsSortMode.None);
foreach (var canvas in allCanvases) {
canvas.worldCamera = Camera.main;
}
}
What that does is it finds all canvases in the newly-loaded scene and sets their camera to the main one. Using this method you can even make two canvases work simultaneously, although I’d recommend putting them on different sorting layers so that you can tightly control which is rendered ‘in front’.