Forum rules - please read before posting.

Remapping Controls for Console (Switch) Platform

Hi all!

I'm working with a friend of mine who developed his game using AC for PC platforms but he now wants to port the game to Switch. Since he doesn't know much about programming, he asked me to help him out. I meant this because I work as a programming professionally and know quite a bit about Unity as I've been working with it for years. AC however is completely new to me so I'm learning what I can about it on the fly.

So, we got his game running on the Switch and I wrote some code to manually override Input so that we can leverage the NintendoSDK's Input system. This works when the game first launches into the initial scene as there is menu-ing that pops up but as soon as it loads into the next scene all input stops working. I set up my code using the following tutorial along with what is in the manual/API:
https://www.adventurecreator.org/tutorials/remapping-controls-game

The way I structured my code is to create this script in the first scene then set the object to get destroyed when a new scene loads. In theory, this means this override should be persistent but I suspect that AC must re-initializes the input in some way when each new scene loads.

If this is the case, what is the best way to accomplish what I'm looking to do? For reference, here is some code that I wrote (all Switch related code has been redacted as I believe it all to be working properly).

Here is my script that overrides the input:
`
public class SwitchInputManager : MonoBehaviour {
///


/// Awakes this instance.
///

private void Awake() {
// Set up Switch controls...
}

    /// <summary>
    /// Starts this instance.
    /// </summary>
    private void Start() {
        // Assign all of our controller delegates
        KickStarter.playerInput.InputGetButtonDownDelegate = InputGetButtonDown;
        KickStarter.playerInput.InputGetButtonUpDelegate = InputGetButtonUp;
        KickStarter.playerInput.InputGetButtonDelegate = InputGetButton;
        KickStarter.playerInput.InputGetAxisDelegate = InputGetAxis;
    }

    private bool InputGetButtonDown(string name) {
        // Do things...
    }
    private bool InputGetButtonUp(string name) {
        // Do things...
    }
    private bool InputGetButton(string name) {
        // Do things...
    }
    private float InputGetAxis(string name) {
        // Do things...
    }
}`

Any help would be greatly appreciated!

Comments

  • Welcome to the community, @geofire92.

    I suspect that AC must re-initializes the input in some way when each new scene loads.

    You're right. The PlayerInput class, which you're hooking into, is part of the GameEngine object - an object that is present in each AC scene, but not itself persistent. Switching to a new scene will clear such overrides.

    I should make this more clear in the Manual - thank you for highlighting it.

    There's a couple of ways to solve this. The first would be to prevent your script from being persistent, and simply place a prefab containing it in each scene.

    The second would be to hook into the OnAfterChangeScene event, so that you can re-map the overrides once AC has re-initialised itself in the new scene. For more on custom events in general, see this tutorial.

    Essentially, though, you'd be looking at something like this:

    using UnityEngine;
    using AC;
    
    public class SwitchInputManager : MonoBehaviour
    {
    
        private void Start ()
        {
            DontDestroyOnLoad (gameObject);
            AssignDelegates ();
        }
    
        private void OnEnable ()
        {
            EventManager.OnAfterChangeScene += OnChangeScene;
        }
    
        private void OnDisable ()
        {
            EventManager.OnAfterChangeScene -= OnChangeScene;
        }
    
        private void OnChangeScene (LoadingGame loadingGame)
        {
            AssignDelegates ();
        }
    
        private void AssignDelegates ()
        {
            KickStarter.playerInput.InputGetButtonDownDelegate = InputGetButtonDown;
            KickStarter.playerInput.InputGetButtonUpDelegate = InputGetButtonUp;
            KickStarter.playerInput.InputGetButtonDelegate = InputGetButton;
            KickStarter.playerInput.InputGetAxisDelegate = InputGetAxis;
        }
    
        // .. etc
    
    }
    
  • Thanks for the quick response! I figured this was the case, I just wanted to confirm it and ensure that there wasn't some other method I should be doing to accomplish this.

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.