Forum rules - please read before posting.

Mouse vs Gamepad custom action problems.

Hiya.  Im having problems doing what seems like it should be a simple task.
From my Options menu, I simply want to allow the user to swap between MouseAndKeyboard controls or KeyboardOrController.

From reading other posts, I understand that I can write a custom Action using: AC.KickStarter.settingsManager.inputMethod = InputMethod.MouseAndKeyboard;

But I cant seem to figure out how to call this script.
I've followed the tutorial for creating Custom Actions, but I cant seem to get that to work either.  Despite following all the steps, nothing ever shows up in my Actions Manager.

I can't figure out what I'm doing wrong.  HELP!!!

Comments

  • Well, it's difficult to say without knowing what it is exactly you've already done.  If you've followed the tutorial, do you have a custom Action script?  Are any error messages pointing in the Console, and have you linked to the folder with it in your Actions Manager?

    Another custom Action tutorial, in which one is made for a custom option field, can be found here.
  • I followed the tutorial but I did not end up with a custom action script.  I have these errors in the console:

    Assets/NickWillikinsAlpha/Scripts/ActionGravityTest.cs(41,41): error CS0305: Using the generic method `UnityEngine.GameObject.GetComponent<T>()' requires `1' type argument(s)

    and

    Instance of ActionGravityTest couldn't be created. The the script class needs to derive from ScriptableObject.
    UnityEngine.ScriptableObject:CreateInstance(String)
    AC.AdventureCreator:RefreshActions() (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:553)
    AC.AdventureCreator:OnGUI() (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:349)
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

  • If you've made an error in your script, it won't compile and won't be visible to AC's Actions Manager.

    It sounds like you haven't provided a class type in the GetComponent function - see this entry of Unity's documentation for more on its use.  However, without knowing the exact code it's not possible to say for sure.  Please post the code line that the error message is referring to.  What's on line 41 of your custom Action?


  • Man, I just cannot get the hang of custom action scripts!
    Im still trying to create a custom action that allows the player to set their input type. I tried to write a simple custom action that simply allows an action to set the input type as Mouse and Keyboard, but I keep getting this error:

    '..Action_setKeyboardMouse.cs' must derive from AC's Action class in order to be available as an Action.

    Here is my script:
    /*
    *
    * Adventure Creator
    * by Chris Burton, 2013-2019
    *
    * "ActionChangeInput.cs"
    *
    * This is a blank action template.
    *
    */

    using UnityEngine;

    if UNITY_EDITOR

    using UnityEditor;

    endif

    namespace AC
    {

    [System.Serializable]
    public class ActionSetMouseKeyboard : Action
    {
    
        // Declare variables here
    
    
        public ActionSetMouseKeyboard ()
        {
            this.isDisplayed = true;
            category = ActionCategory.Custom;
            title = "Engine: Set Mouse and Keyboard";
            description = "Set the input type to Mouse & Keyboard.";
        }
    
    
        override public float Run ()
        {
            KickStarter.settingsManager.inputMethod = InputMethod.MouseAndKeyboard;         
    
        }
    
    
        override public void Skip ()
        {
    
    
             Run ();
        }
    
    
        #if UNITY_EDITOR
    
        override public void ShowGUI ()
        {
            // Action-specific Inspector GUI code here
    
            AfterRunningOption ();
        }
    
    
        public override string SetLabel ()
        {
            // (Optional) Return a string used to describe the specific action's job.
    
            return string.Empty;
        }
    
        #endif
    
    }
    

    }

  • The Action's class name must match it's filename. Your script shows the class name is "ActionSetMouseKeyboard", but your error message suggests the filename is "Action_setKeyboardMouse". Rename this to match the class name and restart Unity.

  • Well that seems to have removed the error (Thank you!), but now Im facing a different issue.
    I'm using Salsa for Lipsync and facial expressions (Which works great!) but it requires that I set the Custom Action Scripts directory to a specific path:
    "..Assets\Crazy Minnow Studio\Addons\AdventureCreator\Actions"

    So instead of creating a new directory for my own custom actions (As shown in the tutorials) I dropped my new custom action into this folder. However, when I do this my project opens WITHOUT Adventure Creator. (Removing the script from the folder seems to remedy that problem)

    Can I set multiple folder directories for custom action scripts? I'm scared that changing the directory will eliminate/disconnect the custom SALSA based actions Ive been using.

    Thoughts?

  • it requires that I set the Custom Action Scripts directory to a specific path:

    Why is that? If this is a custom Action, they do need to all be in the same place, but their location should be unimportant. You could likely ignore their advice and just drag the Action scripts they provide into your own custom directory.

    However, when I do this my project opens WITHOUT Adventure Creator.

    If there's a compilation error, all custom tools (not just AC) will fail to load. Check your Console for error messages.

  • Anyone willing to just write a quick script for me since I cant seem to get the hang of this? A;; I want is a custom action script that will set the input control method as Mouse & Keyboard. (I'll also need another that sets the input method as Controller, but Im hoping once I see a script for Keyboard/Mouse I can figure the rest out for myself.

    I have no idea what I'm doing wrong.
    Thanks

  • Your original script should set the input method Mouse And Keyboard - what's the issue, exactly?

    To also change the input method to Keyboard Or Controller, it'd be easier to simply expose the intended input method as a control in the same Action. Something like:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    
    namespace AC
    {
    
        [System.Serializable]
        public class ActionSetMouseKeyboard : Action
        {
    
            public InputMethod newInputMethod = InputMethod.MouseAndKeyboard;
    
            public ActionSetMouseKeyboard ()
            {
                this.isDisplayed = true;
                category = ActionCategory.Input;
                title = "Change input method";
                description = "Change the input method.";
            }
    
            override public float Run ()
            {
                KickStarter.settingsManager.inputMethod = newInputMethod;
            }
    
            #if UNITY_EDITOR
    
            override public void ShowGUI ()
            {
                newInputMethod = (InputMethod) EditorGUILayout.EnumPopup ("New input method:", newInputMethod);
                AfterRunningOption ();
            }
    
            #endif
    
        }
    
    }
    

    (I moved it to the Input category and tidied up, too)

  • Okay, so Ive copied that script over exactly and named the script appropriately, but Im still getting an error:

    Instance of ActionSetMouseKeyboard couldn't be created. The the script class needs to derive from ScriptableObject.
    UnityEngine.ScriptableObject:CreateInstance(String)
    AC.AdventureCreator:RefreshActions() (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:563)
    AC.AdventureCreator:OnEnable() (at Assets/AdventureCreator/Scripts/Managers/Editor/AdventureCreator.cs:48)
    UnityEditorInternal.InternalEditorUtility:LoadSerializedFileAndForget(String)
    UnityEditor.WindowLayout:LoadWindowLayout(String, Boolean)

    Also, this error:
    Assets/Crazy Minnow Studio/Addons/AdventureCreator/Actions/ActionSetMouseKeyboard.cs(23,31): error CS0161: `AC.ActionSetMouseKeyboard.Run()': not all code paths return a value

    As you can see, I'm still using the path inside the CrazyMinnow plug in folder as my Custom Action Scripts folder, but I assume that shouldnt make a difference as long as Ive set that folder as the default for custom action scripts, which I have.

  • My mistake. Replace the Run function with the following:

    override public float Run ()
    {
        KickStarter.settingsManager.inputMethod = newInputMethod;
        return 0f;
    }
    

    Hopefully that should solve both errors.

  • Fantastic! This is working perfectly! Thank you so much!

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.