Language

There is already a virtual axis named 'x' registered

Hello,

I'm trying to create a game that uses touch input. The panel that the touch inputs are on is loaded when I enter the play scene. I'm trying to set it up so that I can change scenes (to the main menu after exiting play scene), then come back to the play scene. On the first time around, everything loads and functions properly. But when I exit to the main menu, then re enter the play scene, I get the error "There is already a virtual axis named (name of axis) registered." Here is the code segment that creates the virtual axes:

// create new axes based on axes to use
if (m_UseX)
{
m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
}
if (m_UseY)
{
m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
}
}

So far I've tried checking if the axis already exist before registering them with the following modification to the previous function:

2 Replies

Okay so I've come up with a solution that appears to be working and isn't throwing any errors... Though I'm not entirely sure why this works any better than what I tried earlier. Anyway, here's the code modification:

public void RegisterVirtualAxis(CrossPlatformInputManager.VirtualAxis axis)
{
// check if we already have an axis with that name and log and error if we do
if (m_VirtualAxes.ContainsKey(axis.name))
{
UnRegisterVirtualAxis(axis.name);
RegisterVirtualAxis(axis);
//Debug.LogError("There is already a virtual axis named " + axis.name + " registered.");
}

dude i need help. I am getting this error "There's already mouse X registered" and the axis doesn't work anymore. I tried your edition in VirtualInput.cs script by standard assets, still the axis doesnt work for me :((