- Home /
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:
void CreateVirtualAxes() { // set axes to use m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal); m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
// 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:
void CreateVirtualAxes()
{
// set axes to use
m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
// create new axes based on axes to use
if (m_UseX)
{
if(!CrossPlatformInputManager.AxisExists(horizontalAxisName))
{
m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
}
}
if (m_UseY)
{
if (!CrossPlatformInputManager.AxisExists(verticalAxisName))
{
m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
}
}
}
but this throws a null reference error saying that m_HorizontalVirtualAxis is not set to an instance of an object.
I've also tried removing the virtual axis when changing scenes so that they might be re registered when the play scene is loaded up again but this isn't working either.
public void RemoveAxes()
{
CrossPlatformInputManager.UnRegisterVirtualAxis(horizontalAxisName);
CrossPlatformInputManager.UnRegisterVirtualAxis(verticalAxisName);
}
Any ideas? Many thanks in advance :)
Answer by GameDev_Chuck · Jul 11, 2015 at 10:22 PM
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:
void CreateVirtualAxes()
{
// set axes to use
m_UseX = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyHorizontal);
m_UseY = (axesToUse == AxisOption.Both || axesToUse == AxisOption.OnlyVertical);
// create new axes based on axes to use
if (m_UseX)
{
if (CrossPlatformInputManager.AxisExists(horizontalAxisName))
{
CrossPlatformInputManager.UnRegisterVirtualAxis(horizontalAxisName);
}
m_HorizontalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(horizontalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_HorizontalVirtualAxis);
}
if (m_UseY)
{
if (CrossPlatformInputManager.AxisExists(verticalAxisName))
{
CrossPlatformInputManager.UnRegisterVirtualAxis(verticalAxisName);
}
m_VerticalVirtualAxis = new CrossPlatformInputManager.VirtualAxis(verticalAxisName);
CrossPlatformInputManager.RegisterVirtualAxis(m_VerticalVirtualAxis);
}
}
Just like to say thank you for this, for some reason $$anonymous$$e just would not register, using your above code done the trick, now it's all working ..
@GameDev_Chuck I was having the same issue and your piece of code resolved the problem. Thank you very much.
@GameDev_Chuck I was having the same issue and your piece of code resolved the problem. Thank you very much.
You can also try to unregister and register again...
public void RegisterVirtualAxis(CrossPlatformInput$$anonymous$$anager.VirtualAxis axis)
{
// check if we already have an axis with that name and log and error if we do
if (m_VirtualAxes.Contains$$anonymous$$ey(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 :((
Have you checked your input settings? (Edit->Project Settings-> Input->Axes) Sounds like you may have conflicting names.
please watch and tell me what can be the problem I tried your way too, doesnt work for me. https://www.youtube.com/watch?v=Xi6-ZV38IR0&feature=youtu.be
What is happening when you click the checkbox for touchpad? What's in the function that's called? $$anonymous$$y issue was when I was changing scenes. Yours might be unrelated.
Thank you very much, it works without problems. I needed this for two joysticks, one for player movement, and one for player view.
Answer by CrazyZombieKiller · Dec 24, 2016 at 07:10 PM
Hey,
The error message didn't seem to make sense. I just copied the steps from a working tutorial. So I closed down Unity and restarted. Problem fixed (again).
Peter
Debug.LogError("There is already a virtual axis named " + axis.name + " registered."); with UnRegisterVirtualAxis(axis.name); RegisterVirtualAxis (axis);
Answer by nextage575 · Nov 15, 2019 at 09:13 AM
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)) { //Debug.LogError("There is already a virtual axis named " + axis.name + " registered."); m_VirtualAxes.Remove(axis.name); m_VirtualAxes.Add(axis.name, axis); if (!axis.matchWithInputManager) { m_AlwaysUseVirtual.Add(axis.name); } } else { // add any new axes m_VirtualAxes.Add(axis.name, axis); // if we dont want to match with the input manager setting then revert to always using virtual if (!axis.matchWithInputManager) { m_AlwaysUseVirtual.Add(axis.name); } } } Replace this piece of code with yours.Blockquote
Your answer