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’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Handling control IDs for dynamic controls.

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

  1. joshua2880


    Aug 14, 2019
    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.