Forum rules - please read before posting.

Rewired: Using Control Mapper

Hi folks,

Is there a tried & true way to use Rewired's Control Mapper in an AC project?

BTW I'm not asking how to get Rewired itself working, I have had that working in my AC game for a few years (thanks to the script on the wiki), I am looking for advice as to how the player can actually access, and make use of, Control Mapper.

Does it rely on AC send message or call event actions for example, and how would control be transferred to the Control Mapper UI from AC? It's as unclear as it is important. After all, without using CM there'd barely be any benefit using Rewired in the first place, so advice welcome please.

Comments

  • The integration script doesn't deal with Control Mapper - so there's no standard for what it "relies" on in terms of AC. It should be possible to use those Actions to trigger the ControlMapper's "Open" function, but can also be done through scripting or through Button onClick events, as covered in Rewired's docs.

    To prevent control over AC when using CM, the "Engine: Manage systems" Action can be used to selectively-disable parts of AC during this time.

    Ideally, the CM UI prefab would be linked to an AC Unity UI Menu, but I'm not sure if CM supports being spawned in at runtime. Having it be in the scene and set to "Unity UI In Scene" may be a necessary compromise.

  • You're right Chris, I've simply called ControlMapper's "open" function with a Send Message action, and this works in regards to opening the ControlMapper screen.

    I have created a menu called Controls and the Send message action is done via an "ActionList when turn on" for the Controls menu. I changed the Menu to "Unity UI in scene", though AC complains that "no Linked Canvas can be found!" as ControlMapper disables the canvas by default. This is no big deal though.

    Rewired comes with an Event System integration for Unity UI - I was only able to get it working by dropping this into my scene. AC mentions that this may cause problems - I have only tested this one scene so far, which is simply the main menu, so I'm not sure if it will cause issue with general gameplay or not, I will report back here if so.

    Not sure if I need to set e.g. First selected Element, or if CM handles that on it's own? Also should I make a prefab of this ControlMapper and drop it in all my scenes, or should I create ControlMapper the usual way (in each scene) then manually add the Constant ID to CM?

    Sorry for the barrage of info and questions here, just trying to avoid headaches.

  • Rewired comes with an Event System integration for Unity UI - I was only able to get it working by dropping this into my scene. AC mentions that this may cause problems

    A local EventSystem will override AC's EventSystem for the duration of that scene. AC's own EventSystem allows for more robust direct-navigation of UI elements (and preventing mouse interactions while doing so).

    This is made possible by AC's Optional Mouse Input Module, which you should find attached to AC's EventSystem. If this is not present, you may find issue when it comes to directly-navigating AC menus. I'd suggest looking into a way of combining both EventSystems into one - possibly by enabling/disabling components depending on whether the ControlMapper menu is on.

    Not sure if I need to set e.g. First selected Element, or if CM handles that on it's own?

    First Selected Element will only apply if the Selectable components of the UI are linked to the Menu as Menu Elements. You can manually select a given Selectable by calling its Select function, however.

    Also should I make a prefab of this ControlMapper and drop it in all my scenes, or should I create ControlMapper the usual way (in each scene) then manually add the Constant ID to CM?

    If it's necessary to place CM into the scene, it should still be made a prefab so that any change you make applies to all copies. This includes the Constant ID number, which will need to be the same for all scenes its used in.

  • A local EventSystem will override AC's EventSystem for the duration of that scene. AC's own EventSystem allows for more robust direct-navigation of UI elements (and preventing mouse interactions while doing so).

    This is made possible by AC's Optional Mouse Input Module, which you should find attached to AC's EventSystem. If this is not present, you may find issue when it comes to directly-navigating AC menus. I'd suggest looking into a way of combining both EventSystems into one - possibly by enabling/disabling components depending on whether the ControlMapper menu is on.

    This screenshot is the inspector of the Unity UI EventSystem integration prefab supplied with Rewired. I assume the important bit is the Rewired Standalone Input Module component. Perhaps there's a way to add this to Adventure Creator's EventSystem?

    Screen

  • You can create a custom EventSystem for AC by assigning it as a prefab at the top of the Menu Manager.

    However, both AC's Optional Mouse Input Module, and Rewired's Standalone Input Module, are both replacements for Unity's Standalone Input Module - you can't use both at once.

    My suggestion above is to try having both on a prefab, but only one active at a time. This can be done manually at first by clicking their checkboxes in the Inspector at runtime - just to see if that gives the control you're looking for. This could be automated through script if successful.

  • I have tested Rewired's Standard Input Module by having it already present in a normal gameplay scene and haven't run into any issues. However, your idea sounds wise e.g for using AC's EventSystem for preventing mouse interactions when using direct-navigation UI.

    Where is AC's EventSystem "spawned" from in the project/assets folders? Is there a pre-made prefab I can just add the relevant Rewired components to then assign that in the Menu Manager, or shall I just make it from scratch?

  • AC generates its own EventSystem - it'll only spawn a prefab in if one is assigned in the Menu Manager.

  • edited March 2022

    Ok, I got it working in the scene. To test, I used object: call event on the EventSystem like this:

    RewiredStandardInputModule. enabled = false
    Optional Mouse Input Module.enabled = true (and vice versa)

    This switches the components off or on. If I remember rightly though, I can't use Call Event from an Action List asset so ideally it would have to be scripted, though I am still clueless on writing scripts. Maybe there is a way to use Send Message on the prefab?

  • edited March 2022

    Here's a script, ModuleController.cs, that you can attach to the prefab:

    using UnityEngine;
    using UnityEngine.EventSystems;
    
    public class ModuleController : MonoBehaviour
    {
    
        public StandaloneInputModule acModule;
        public StandaloneInputModule rewiredModule;
    
        public void SetAC ()
        {
            acModule.enabled = true;
            rewiredModule.enabled = false;
        }
    
        public void SetRewired ()
        {
            rewiredModule.enabled = true;
            acModule.enabled = false;
        }
    
    }
    

    Assign the two modules in its Inspector, and you can then call its SetAC / SetRewired functions using the "Object: Send message" Action.

  • Thank you, but Unity doesn't seem to like that false bool on line 13. I get this:

    Assets\Game\ModuleController.cs(13,25): error CS0029: Cannot implicitly convert type 'bool' to 'UnityEngine.EventSystems.StandaloneInputModule'

  • Just a typo. Try it now.

  • edited March 2022

    Yes, the error's gone now. I can't get it to work though I'm afraid, maybe I'm missing something?

    To summarise:
    I have a menu called Controls, I open this and it's "when opened" action list does a Send Message to Control Mapper to open that (this works fine), I also do:
    Send Message: Custom: SetRewired
    to call that SetRewired function from your script on the EventSystem prefab, but it does not turn on the Rewired Input Module (or turn off the AC one).

    I have checked the Constant ID on the EventSystem when it is spawned in the scene and it is the same ID as the one referenced in the Send Message action, so I'm not sure why it doesn't work really, everything seems correct.

    Edit: I will add though, when I first corrected the script, for some reason all my Constant ID's in the scene were changed - every single one in the scene. I did not save, restarted Unity, then everything was thankfully back to normal. Not sure if this has any significance, but I've never seen it happen before so I thought I'd mention it.

  • Insert the following inside the SetRewired function:

    Debug.Log ("Received message", gameObject);
    Debug.Log ("Enabled Rewired module", rewiredModule);
    

    That should show a pair of Console logs when the SetRewired message is sent. If you click on these logs, they'll ping the object they affect. Are they pinging the EventSystem in the Hierarchy, or the original prefab?

  • Oh wait, sorry, brain fog moment - I haven't assigned the modules in the inspector.

    I just tried to do it though, and it won't allow the Rewired Module to be assigned, it will only allow AC's Optional Mouse Input Module.

  • Try replacing:

    public StandaloneInputModule rewiredModule;
    

    with:

    public BaseInputModule rewiredModule;
    
  • You're the absolute man, it works. Thanks again.

    In fact I think I could go back & use this for all Unity UI menus now - you may recall a while back I was having difficulty navigating Unity UI Inventory because Rewired wouldn't work in menus. Now it does.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.