Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

set to an instance instead of object error

Discussion in 'Scripting' started by Brownie32, Aug 17, 2022.

  1. Brownie32

    Brownie32

    Joined:
    Aug 13, 2022
    Posts:
    5
    i get the error "object refrence set to an instance instead of an object" error on this script (note, the script was auto generated)
    the script:
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine.InputSystem;
    using UnityEngine.InputSystem.Utilities;
    public partial class @PlayerInput : IInputActionCollection2, IDisposable
    {
    public InputActionAsset asset { get; }
    public @PlayerInput()
    {
    asset = InputActionAsset.FromJson(@"{
    ""name"": ""PlayerInput"",
    ""maps"": [
    {
    ""name"": ""OnFoot"",
    ""id"": ""bf7ce9e9-ecbb-4249-ad67-e96fadd505f3"",
    ""actions"": [
    {
    ""name"": ""Movement"",
    ""type"": ""Value"",
    ""id"": ""7d7c4465-bc48-4f4b-b24b-057dd7f0f524"",
    ""expectedControlType"": ""Vector2"",
    ""processors"": """",
    ""interactions"": """",
    ""initialStateCheck"": true
    },
    {
    ""name"": ""Jump"",
    ""type"": ""Button"",
    ""id"": ""a85c19df-e920-478e-bb1c-4c5cd003a3eb"",
    ""expectedControlType"": ""Button"",
    ""processors"": """",
    ""interactions"": """",
    ""initialStateCheck"": false
    }
    ],
    ""bindings"": [
    {
    ""name"": """",
    ""id"": ""edfa49f4-5c15-4e61-83ab-f8297a7f1fda"",
    ""path"": """",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": false
    },
    {
    ""name"": ""WASD"",
    ""id"": ""54bceec1-d1e7-493a-976a-2b2facbcf03b"",
    ""path"": ""2DVector"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": true,
    ""isPartOfComposite"": false
    },
    {
    ""name"": ""up"",
    ""id"": ""2f23f6b7-fdaf-440a-ae95-3f341598b778"",
    ""path"": ""<Keyboard>/w"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": ""down"",
    ""id"": ""8ad30d3d-7594-42db-abde-c0b2cbe3c0da"",
    ""path"": ""<Keyboard>/s"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": ""left"",
    ""id"": ""85b90cf1-70ad-44d3-86da-06d0d1c24bf3"",
    ""path"": ""<Keyboard>/a"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": ""right"",
    ""id"": ""6977b9aa-3b55-43eb-bd83-40e976647f25"",
    ""path"": ""<Keyboard>/d"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": ""Left Stick"",
    ""id"": ""999d4790-926c-43db-8282-99b1f1271a0d"",
    ""path"": ""2DVector"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": true,
    ""isPartOfComposite"": false
    },
    {
    ""name"": ""up"",
    ""id"": ""22404c1d-1c22-4f38-bdef-9e6a9b9d68ec"",
    ""path"": ""<Gamepad>/leftStick/up"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": ""down"",
    ""id"": ""1acfc925-a6c7-4cce-b088-a5c6009a051c"",
    ""path"": ""<Gamepad>/leftStick/down"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": ""left"",
    ""id"": ""6f0f4af2-d284-4c6a-a25c-883194256075"",
    ""path"": ""<Gamepad>/leftStick/left"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": ""right"",
    ""id"": ""8c58c7fd-3aef-4391-bf55-b7bf83ef302a"",
    ""path"": ""<Gamepad>/leftStick/right"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Movement"",
    ""isComposite"": false,
    ""isPartOfComposite"": true
    },
    {
    ""name"": """",
    ""id"": ""f868a474-6865-4dba-add9-1a7aaa18fb7b"",
    ""path"": ""<Keyboard>/space"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Jump"",
    ""isComposite"": false,
    ""isPartOfComposite"": false
    },
    {
    ""name"": """",
    ""id"": ""881e9bc3-fb34-46c2-bf9e-1534edb79438"",
    ""path"": ""<Gamepad>/buttonSouth"",
    ""interactions"": """",
    ""processors"": """",
    ""groups"": """",
    ""action"": ""Jump"",
    ""isComposite"": false,
    ""isPartOfComposite"": false
    }
    ]
    }
    ],
    ""controlSchemes"": []
    }");
    // OnFoot
    m_OnFoot = asset.FindActionMap("OnFoot", throwIfNotFound: true);
    m_OnFoot_Movement = m_OnFoot.FindAction("Movement", throwIfNotFound: true);
    m_OnFoot_Jump = m_OnFoot.FindAction("Jump", throwIfNotFound: true);
    }
    public void Dispose()
    {
    UnityEngine.Object.Destroy(asset);
    }
    public InputBinding? bindingMask
    {
    get => asset.bindingMask;
    set => asset.bindingMask = value;
    }
    public ReadOnlyArray<InputDevice>? devices
    {
    get => asset.devices;
    set => asset.devices = value;
    }
    public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
    public bool Contains(InputAction action)
    {
    return asset.Contains(action);
    }
    public IEnumerator<InputAction> GetEnumerator()
    {
    return asset.GetEnumerator();
    }
    IEnumerator IEnumerable.GetEnumerator()
    {
    return GetEnumerator();
    }
    public void Enable()
    {
    asset.Enable();
    }
    public void Disable()
    {
    asset.Disable();
    }
    public IEnumerable<InputBinding> bindings => asset.bindings;
    public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
    {
    return asset.FindAction(actionNameOrId, throwIfNotFound);
    }
    public int FindBinding(InputBinding bindingMask, out InputAction action)
    {
    return asset.FindBinding(bindingMask, out action);
    }
    // OnFoot
    private readonly InputActionMap m_OnFoot;
    private IOnFootActions m_OnFootActionsCallbackInterface;
    private readonly InputAction m_OnFoot_Movement;
    private readonly InputAction m_OnFoot_Jump;
    public struct OnFootActions
    {
    private @PlayerInput m_Wrapper;
    public OnFootActions(@PlayerInput wrapper) { m_Wrapper = wrapper; }
    public InputAction @movement => m_Wrapper.m_OnFoot_Movement;
    public InputAction @Jump => m_Wrapper.m_OnFoot_Jump;
    public InputActionMap Get() { return m_Wrapper.m_OnFoot; }
    public void Enable() { Get().Enable(); }
    public void Disable() { Get().Disable(); }
    public bool enabled => Get().enabled;
    public static implicit operator InputActionMap(OnFootActions set) { return set.Get(); }
    public void SetCallbacks(IOnFootActions instance)
    {
    if (m_Wrapper.m_OnFootActionsCallbackInterface != null)
    {
    @Movement.started -= m_Wrapper.m_OnFootActionsCallbackInterface.OnMovement;
    @Movement.performed -= m_Wrapper.m_OnFootActionsCallbackInterface.OnMovement;
    @Movement.canceled -= m_Wrapper.m_OnFootActionsCallbackInterface.OnMovement;
    @Jump.started -= m_Wrapper.m_OnFootActionsCallbackInterface.OnJump;
    @Jump.performed -= m_Wrapper.m_OnFootActionsCallbackInterface.OnJump;
    @Jump.canceled -= m_Wrapper.m_OnFootActionsCallbackInterface.OnJump;
    }
    m_Wrapper.m_OnFootActionsCallbackInterface = instance;
    if (instance != null)
    {
    @Movement.started += instance.OnMovement;
    @Movement.performed += instance.OnMovement;
    @Movement.canceled += instance.OnMovement;
    @Jump.started += instance.OnJump;
    @Jump.performed += instance.OnJump;
    @Jump.canceled += instance.OnJump;
    }
    }
    }
    public OnFootActions @OnFoot => new OnFootActions(this);
    public interface IOnFootActions
    {
    void OnMovement(InputAction.CallbackContext context);
    void OnJump(InputAction.CallbackContext context);
    }
    }
     
  2. TheDevloper

    TheDevloper

    Joined:
    Apr 30, 2019
    Posts:
    69
    please use code tags
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Fix that first. Hand-generate what you think you need, make 100% sure it compiles, then you can cross-check if your code generator has bugs by comparing back and forth.

    If you didn't write the code generator, then you need to make sure it emits code that is consistent with the C# level expected by Unity.
     
  4. Brownie32

    Brownie32

    Joined:
    Aug 13, 2022
    Posts:
    5
    ok thanks
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Kurt this is code generated by Unity's own InputActionsAsset.
    First off that's definitely not what the error says. It says completely the opposite. Please note the filename and line number from your error, they are very important. Also be sure that if you have made any code changes to the Input Actions Asset file that you ensure the C# generated file is regenerated.
     
    Kurt-Dekker likes this.
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Thanks for that call-out Praetor... didn't even look at unformatted code. :)
     
    PraetorBlue likes this.