Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Games entirely made in Unity UI - bad idea?

Discussion in 'UGUI & TextMesh Pro' started by casimps1, Oct 17, 2015.

  1. casimps1

    casimps1

    Joined:
    Jul 28, 2012
    Posts:
    254
    I have some ideas for some pretty simple 2D puzzle games and it occurs to me that it might make sense to treat all the game elements entirely as UI objects and not use 2D Sprite objects at all. Is this a bad idea for any reason?

    I know that if you have any type of 2D game that involves moving a camera and/or a world that extends beyond one screen's worth of objects, then 2D Sprites and Cameras make perfect sense and seems the obvious choice. But simpler single-screen games (think match-3 games, connect-the-dots games, card games, etc.) make me wonder if it's worth it to go completely UI and have access to all the nice new event system stuff (which from what I can tell isn't easily hooked into Unity's 2D system).

    Thoughts on pros/cons of going exclusively UI?
     
  2. McMayhem

    McMayhem

    Joined:
    Aug 24, 2011
    Posts:
    443
    Well I certainly don't see any reason why you couldn't, given that your examples are games that feature mid-to-low graphical complexity. It certainly wouldn't hurt to investigate the matter, especially if it leads to you finding places where the UI performs less efficiently than it should. I imagine it would be of great help to the developers to get that kind of information.

    Although, there are certainly drawbacks to using specific tools outside of their designed intentions. My guess is that there is some kind of optimization going on with sprites over UI in order to provide a broader allowance of objects per frame. I suppose it's possible they haven't applied the same method to the UI code since it's mostly intended for, well UI stuff.

    The only specifics I can think of is that you would lose out on some of the cooler easy-to-use features such as 2D physics that you would then have to simulate yourself. Although given the game examples you presented, I doubt that would be something you need to worry about.

    A perfectly good question though, and one I'd love to know the answer to.
     
  3. casimps1

    casimps1

    Joined:
    Jul 28, 2012
    Posts:
    254
    I actually had one project I was working on where several UI buttons were bubbles and I needed them to float around and push away from each other and the screen edges. I was curious if I could do it with physics so I ended up adding rigidbodies, 2D colliders, and attractors to the CanvasRenderers, and it all worked great.

    So, I'm not even sure that physics is out of the question in this case.
     
    McMayhem likes this.
  4. McMayhem

    McMayhem

    Joined:
    Aug 24, 2011
    Posts:
    443
    Interesting! Aside from the question at hand, that has massive implications for fancy UI design. I'll have to give that a try.

    Did you manage to profile the performance with those components added? Does it make much of a difference at all?
     
  5. casimps1

    casimps1

    Joined:
    Jul 28, 2012
    Posts:
    254
    I actually did have some performance problems at first. I had 6 rigidbody bubbles each with attractors, plus another 8 attractors that served to push the bubbles around randomly and away from edges. Apparently that setup was enough to cause problems even on a fairly fast Windows PC, which did surprise me a bit.

    When I profiled it I remember seeing that all the time was spent in one particular Physics call, but I don't remember the name and could never find any information about that call anywhere. The fact that the slowdown came from a Physics call makes me believe that it had nothing to do with UI vs. 2D though.

    Anyway, I just ended up increasing the Fixed Timestep a bit so physics wasn't calculated as frequently and then everything ran fast enough on my target device that I didn't care anymore about optimization.