New Unity Input System Integration

FullMe7alJacke7

New member
I'm having trouble figuring out how to hook into the new unity input system.

I tried using the conditional IsMouseDown which is not getting triggered, I would imagine due to the changes they made in how the unity input events are handled.

I am attempting to hook into these via script and just send a message to the BT's Has Received Event instead but I can't seem to figure out how I would go about that.

I was thinking something along the lines of
Code:
 controls.Default_ActionMap.LeftClick.performed += context => behavior.SendEvent(controls.Default_ActionMap.LeftClick.name);
My question is how would I hook it up to register to the event, if that line will indeed work.

I would imagine to register to the event it is simply
Code:
 behavior.RegisterEvent<object>("LeftClick", myActionHere );

The idea was that this will be a behavior tree for how to handle input depending on game state as I handle multiple buttons that have multiple functionality depending on whats going on in the game.

EDIT: After more fiddling around this is what I currently have but I am getting StackOverflowExceptions.

Code:
        Action action = () => behavior.SendEvent(controls.Default_ActionMap.LeftClick.name);
        behavior.RegisterEvent("LeftClick", action);
        controls.Default_ActionMap.LeftClick.performed += context => action();
 
Last edited:

Justin

Administrator
Staff member
I haven't used the new input system yet but your last edit looks like it should work. What is the stack overflow?
 

FullMe7alJacke7

New member
Hello, sorry for the delayed reply!

So here is a screenshot of the console log.

The first error to show up says this.
StackOverflowException thrown during execution of 'Performed' callback on action 'Default_ActionMap/LeftClick[/Mouse/leftButton]'
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at C:/buildslave/unity/build/Modules/Input/Private/Input.cs:120)
The second error thrown says this. (Plus about 1000 more lines I didn't think would be necessary to show.)
StackOverflowException: The requested operation caused a stack overflow.
System.Environment.get_Is64BitProcess () (at <a8ed250850854b439cedc18931a314fe>:0)
System.String.EqualsHelper (System.String strA, System.String strB) (at <a8ed250850854b439cedc18931a314fe>:0)
System.String.Equals (System.String value) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Collections.Generic.GenericEqualityComparer`1[T].Equals (T x, T y) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) (at <a8ed250850854b439cedc18931a314fe>:0)
System.Collections.Generic.Dictionary`2[TKey,TValue].TryGetValue (TKey key, TValue& value) (at <a8ed250850854b439cedc18931a314fe>:0)
BehaviorDesigner.Runtime.Behavior.GetDelegate (System.String name, System.Type type) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
BehaviorDesigner.Runtime.Behavior.SendEvent (System.String name) (at <8273d6b105784beab3b1f76a8d030c0c>:0)
InputListener+<>c__DisplayClass3_0.<Awake>b__0 () (at Assets/Phantom Dragon Studio/_Scenes/Demonstration/InputListener.cs:22)
It seems to be happening from line 22 according to the end of the second quote. The SendEvent line.

Code:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using BehaviorDesigner.Runtime;
using UnityEngine;
using UnityEngine.Serialization;

public class InputListener : MonoBehaviour
{ 
    [SerializeField] private DefaultActions controls; 
    private BehaviorTree behavior;

    private delegate void DoStuff();
    
    void Awake()
    {
        controls = new DefaultActions();
        controls.Enable();
        behavior = this.GetComponent<BehaviorTree>();
        
        Action action = () => behavior.SendEvent(controls.Default_ActionMap.LeftClick.name);
        behavior.RegisterEvent("LeftClick", action);
        controls.Default_ActionMap.LeftClick.performed += context => action();
    }

    private void NewStuff()
    {
        print("Stuff");
    }
    
}

1567
 

Justin

Administrator
Staff member
That almost seems like a bug in the new input system. It doesn't look like there are any calls that you are making that are repeating.
 
Top