Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GameDev_Chuck · Jul 11, 2015 at 10:17 PM · cross-platform

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 :)

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
12
Best Answer

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);

     }
 }
Comment
Add comment · Show 16 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Griffo · Aug 30, 2015 at 02:14 PM 0
Share

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 ..

avatar image Inspired2150 · Nov 11, 2015 at 09:18 PM 0
Share

@GameDev_Chuck I was having the same issue and your piece of code resolved the problem. Thank you very much.

avatar image Inspired2150 · Nov 12, 2015 at 04:10 PM 0
Share

@GameDev_Chuck I was having the same issue and your piece of code resolved the problem. Thank you very much.

avatar image seckincengiz · Jan 19, 2016 at 12:56 PM 6
Share

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.");
             }
avatar image Arkaic seckincengiz · May 12, 2016 at 06:52 AM 0
Share

Perfect, thanks a ton!

avatar image Hassan-Pro seckincengiz · Jun 09, 2016 at 07:44 PM 0
Share

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 :((

avatar image GameDev_Chuck Hassan-Pro · Jun 09, 2016 at 07:49 PM 0
Share

Have you checked your input settings? (Edit->Project Settings-> Input->Axes) Sounds like you may have conflicting names.

Show more comments
avatar image Hassan-Pro seckincengiz · Jun 09, 2016 at 08:54 PM 0
Share

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

avatar image GameDev_Chuck Hassan-Pro · Jun 09, 2016 at 09:38 PM 0
Share

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.

Show more comments
Show more comments
avatar image Tecknowser · Feb 23, 2017 at 07:48 PM 0
Share

Thank you very much, it works without problems. I needed this for two joysticks, one for player movement, and one for player view.

Show more comments
avatar image
0

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nextage575 · May 13, 2020 at 06:10 AM 0
Share

Debug.LogError("There is already a virtual axis named " + axis.name + " registered."); with UnRegisterVirtualAxis(axis.name); RegisterVirtualAxis (axis);

avatar image
0

Answer by nextage575 · Nov 15, 2019 at 09:13 AM

Blockquote

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.
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Are there any XCode specific APIs I am required to use to simply port an Android game to iOS, or does Unity cover everything? 0 Answers

Sending games via bluetooth? 1 Answer

UNET - Broadcast Data from Android changes when PC joins Network 1 Answer

Unity3D cross-platform input wireless 1 Answer

Detect/enforce cursor sizes in Unity4's CursorMode.auto? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges