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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Question Optimizing Canvas Event System for thousands of buttons

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

  1. jussch


    Jan 2, 2018
    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


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