Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity UI How do I get a UI prefab to look the way I want in my scene?

Discussion in 'UGUI & TextMesh Pro' started by AcademyOfFetishes, Jun 3, 2019.

  1. AcademyOfFetishes

    AcademyOfFetishes

    Joined:
    Nov 16, 2018
    Posts:
    219
    In my game, I have a map with a bunch of clickable buttons. Each button represents a location. When you click on a button, you're taken to a new scene.

    Since each button will share a lot of functionality, I decided that MapButton should be a prefab. Please let me know if that's a mistake.

    Now my problem is, when I'm editing the prefab, the MapButton looks one way, but when it's in my scene, it looks completely different. It's very easy to make the button look correct when editing it as a prefab, but it looks completely different in play mode, and I have no idea how to get it to look correct there.

    Here's how it looks when I edit it as a prefab:



    That field is just a placeholder graphic that gets replaced at runtime. That lock icon is conditionally set as active.

    These are the proportions I want the button to look like in play mode. But when I hit the play button, it looks like this:



    Here you see the map with multiple buttons on it. The button at the upper right hand corner is the only button with a visible lock icon. But, the lock icon is so big, it spans way outside the boundaries of the button itself. I want it to be contained inside the button and to the proportions I've set in the prefab, but I can't figure out how to do that. How do I make the lock icon fit within its button whether it's a prefab or in a scene?