How to set up UI Toolkit with Input System for context menu that appears at cursor?

I’m working on a game that will have dynamic context menus like in Fire Emblem or RimWorld. I’m using 2021.2.0b6 currently, with UI Toolkit (not the package) and Input System. Two questions:

  1. Whenever I play the game with a UI Document in the scene and Input System enabled, the error:

"InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings."

appears repeatedly. Since I couldn’t find any of the Event System components made for UI Toolkit when I tried to Add Component, I tried using “Input System UI Input Module (Script)” and it made the errors go away.

Is the Input System UI Input Module the new component to use with UI Documents in this version of Unity?

  1. What is the recommended way to use UI Documents? Should I have one document that contains all the different UI pieces, or individual UI Documents for each piece?

If I should use individual UI Documents, I’m not sure what to do to connect this to the Input System. The Input System “Player Input” component allows you to link a single Input System UI Input Module to it. I’ve done this with the one I made. However, if I make additional UI Documents with Input System UI Input Modules, I would not be able to link those to the same Player Input.

Does this mean I should use one UI Document for all UI elements and simply disable the pieces that aren’t needed at the time?

  1. If you are using the New Input System then the “Input System UI Input Module (Script)” is the correct component to use together with the Event System component.

For more info about it: UI support | Input System | 1.1.1

Also make sure that you set Active Input Handling to Input System Package New, it’s under Edit → Project Settings → Player → Other Settings.

  1. As far as I understand you just need the “Input System UI Input Module (Script)” and “Event System” components once in your scene, even for multiple UI Documents. I have the two input components on a seperate game object than my UI Document and it works without a problem.

How you structure your UI is up to you, you can put everthing in one UI Document and hide/show elements or split it out into multiple UI Documents and hide/disable the whole UI Document object.

Personally I would probably put the Gameplay UI in one UI Document and then if I have a Pause Menu or something similar, put that into another UI Document.
Depending on how much UI elements you will have, I might even split the Gameplay UI into two UI Documents one for static visible UI and one that’s for all the popup/overlay UI like the context menu. You can then take advantage of the UI Document sort order to decide in which order the UI Documents are rendered.