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. Dismiss Notice

Choosing between UI and Gameobjects for puzzle games

Discussion in 'General Discussion' started by El-Echi, Feb 24, 2022.

?

UI or Gameobjects

  1. UI

    42.9%
  2. GameObjects

    57.1%
  1. El-Echi

    El-Echi

    Joined:
    Dec 3, 2016
    Posts:
    4
    Hello,

    So I'm currently working on a 2d game with lots of narratives and small puzzle mini games(mainly drag and drop mechanics), the game also should have a sort of pathing and tweening systems.

    And I've been wondering if I should make the mini games using unity's UI since it uses the event system and that would make things easier for drag and drop and related mechanics, or normal gameobjects on the scene for easier position manipulation and particle effects.

    Small note: during the mini games my camera will be fixed

    Is there a recommended way of doing things or more concerns going forward with either approach?
    I would love to hear other people's opinion wether it's better to use unity's UI or just normal 2d gameobjects for gameplay,

    Thanks in advance
     
  2. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,266
    Your best bet is probably normal game objects. There are obscure performance implications of moving and rebuilding canvas layouts. If your only concern is to have a nice event system, then rolling your own using UnityEvents is quite feasible for an intermediate programmer. You could even use the Physics2DRaycaster component on your camera and implement UI events on game objects with standard 2D colliders (like drag and drop).
     
    El-Echi and angrypenguin like this.
  3. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    1,763
    I've heard of the mythical performance implications around redrawing the whole canvas when something is changed inside it. That can be partially addressed by having multiple canvas - one for static UI, one for dynamic UI. I've also never had actual performance issues on desktop platforms and WebGL by going the UI route and I get the drag-and-drop system already made by Unity - OnDrag, OnDrop, etc events. So this would depend more on target platforms.

    One major downside of the UI route is that you can't easily change sorting order of UI objects like you can with the Sprite Renderer's Sorting Order property. Whatever is lower in Hierarchy is displayed first, so you have to mess with sibling indexes. And if the Hierarchy is too complex for that, then you have to start to re-parent stuff or assign the UI object a new Canvas component. A child Canvas can override parent Canvas sorting order for that object. And if you need to do that dynamically say for a UI object highlighting system used in a tutorial, it can get expensive.

    Still, the UI way has worked well for me. And a lot of development time has been saved by using Unity's ready-made drag and drop system.
     
    El-Echi likes this.
  4. El-Echi

    El-Echi

    Joined:
    Dec 3, 2016
    Posts:
    4
    Thank you so much, my target platform is mobile, I've been experimenting with the UI approach so far and I haven't noticed any performance issues yet

    Thank you so much for the reply, I'm planning on trying a simple implementation of both approaches and decide by doing that, Also the PhysicsRaycaster component is sick, I just discovered it
     
  5. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,321
    Frankly, I woulnd't use "unity ui" for dynamic elements unless you have to. It sort of works for more complex layouts but it is not perfect.(also that system is based on gameobjects)

    EventSystem, also, in my opinion, is not a thing worth pursuing.

    So chances are you'll have easier with gameobjects and normal sprites.
     
    El-Echi likes this.
  6. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    9,744
    Echoing gameobjects and sprites. The UI tools will quickly start getting in the way long before they offer any real benefit.
     
    El-Echi likes this.