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

Question Optimizing Canvas Event System for thousands of buttons

Discussion in 'UGUI & TextMesh Pro' started by jussch, Mar 25, 2023.

  1. jussch

    jussch

    Joined:
    Jan 2, 2018
    Posts:
    7
    Hey Unity Forums,

    I've been building an incremental game for the last little bit and I've been doing lots of performance optimizations, and I was hoping if someone could point me in the right direction.

    My game is almost purely done in Unity Canvas, and I have thousands of buttons for the player to interact with. I've done some profiling and I've found that when the mouse is on the screen, The Canvas Event System takes up around 30% of the operations done on a single frame, which is a drop in 40 fps.

    My assumption here is that the event system is trying to detect which buttons the mouse is hovering over and interacting with, and then with the vast quantity of buttons, it takes a bit of time. My question is this, can I either:
    A) Turn off certain elements so that they are not detected by the Canvas Event System without turning the gameObject's active state to false.
    B) Create a custom event system that can optimize the detection of the mouse against the buttons. (IE, if the mouse is in the bottom left quadrant, only check for buttons that could be in that space)
    or C) maybe something else...?

    Thanks for the help!
     
  2. ookk47oo

    ookk47oo

    Joined:
    Mar 17, 2017
    Posts:
    80
    Uncheck the graphic's (e.g. Text, Image without button) RaycastTarget property which should not be responding to mouse event.