0
\$\begingroup\$
private void OnEnable()
{
    Debug.Log(EventSystem.current);
    EventSystem.current.SetSelectedGameObject(gameObject);
}

Very simple script for selecting a UI element on enable. However, EventSystem.current prints null to the console.

Unity 2019.3.15f1

I have an Rewired event system in the scene.

Also tried putting this in an IEnumerator and waiting a frame before logging to the console - no change.

enter image description here enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ Can you post your Event System game object's inspector view? \$\endgroup\$
    – eLTomis
    Aug 4, 2020 at 7:04
  • \$\begingroup\$ Sure. Added to the description. \$\endgroup\$
    – mr-matt
    Aug 4, 2020 at 7:29

1 Answer 1

1
\$\begingroup\$

The problem is that Rewired Event System does not set EventSystem.current. This component allows for multiple independent UIs. Thus, you create multiple Rewired Event Systems, which of them should be set to EventSystem.current?

According to documentation

Rewired also comes with the RewiredEventSystem component which has the additional option to allow multiple Event Systems to run in the scene at the same time. This can be useful if you want to create multiple independent UI's for different Players.

Now, to solve your problem, you should not use Rewired Event System but instead create normal Event System and replace Standalone Input Module with Rewired Standalone Input Module.

According to documentation

You can either create a normal Unity Event System and replace the Standalone Input Module with the Rewired Standalone Input Module component or you can create a Rewired Event System from either of the menu items:

  • GameObject -> Create Other -> Rewired -> UI -> Rewired Event System
  • Window -> Rewired -> Create -> UI -> Rewired Event System
\$\endgroup\$
3
  • \$\begingroup\$ No change again. I have a regular Unity EventSystem in combination with the Rewired Standalone Input Module. Debugging EventSystem.current and RewiredEventSystem.current to console shows both are null. To clarify, it is not EventSystem.current.gameObject that is null (implying that no object is selected), it is EventSystem.current itself. \$\endgroup\$
    – mr-matt
    Aug 4, 2020 at 7:43
  • \$\begingroup\$ Could you provide more screenshot of your setup, then? You said you have regular event system setup, I'd like to see that. \$\endgroup\$
    – eLTomis
    Aug 4, 2020 at 10:01
  • \$\begingroup\$ Added another screenshot. \$\endgroup\$
    – mr-matt
    Aug 5, 2020 at 20:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .