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

Handling control IDs for dynamic controls.

Discussion in 'Immediate Mode GUI (IMGUI)' started by joshua2880, Nov 24, 2019.

  1. joshua2880

    joshua2880

    Joined:
    Aug 14, 2019
    Posts:
    3
    I'm working on building a custom editor window in which the user can instantiate, move and edit different control objects but I am fairly new to editor scripting. As a result, I overlooked control IDs and Unity's event filtering based upon them. This has just started causing me problems. I've mostly been able to resolve them using Event.rawType and implementing my own filtering but I can see this becoming a much greater issue with future features that are going to be difficult or impossible to implement without the use of control IDs. I started this project without really realising the GUI is immediate rather than retained and built each control type as its own object, thinking I could assign control IDs in the constructors. While I can take the time to refactor and separate my event handling from my control states I've come to realise the dynamic nature of my project doesn't work with GUIUtility.GetControlID. It resets and reassigns the IDs for each OnGUI call and relies entirely on the calls being the same amount and in the same order to ensure consistency. Is there any way around this or an alternate method? It kind of seems like a massive floor if there isn't or have I totally misunderstood what's happening.