dream_hst7
New member
Hi everyone,
I'm trying to implement a custom ability called ItemDragAbility that allows the player to grab items with an Inventory component, similar to ItemGrabber. However, the ability does not start when I press the Grab button.
Even though the input is mapped correctly and other abilities work fine, the CanStartAbility() method never returns true because the input check fails. It seems like the Grab key press isn't being recognized by the ability system at all:
In other classes, the same button works as expected.
In VirtualControlsManager.cs, I noticed the following:
value is always returning false, which might be why the ability doesn't start.
I've attached the full code of the ability below (with translated comments).
Any ideas why the input isn't coming through in this ability, or what I might be missing in the setup?
Thanks in advance!
I'm trying to implement a custom ability called ItemDragAbility that allows the player to grab items with an Inventory component, similar to ItemGrabber. However, the ability does not start when I press the Grab button.
Even though the input is mapped correctly and other abilities work fine, the CanStartAbility() method never returns true because the input check fails. It seems like the Grab key press isn't being recognized by the ability system at all:
C#:
return m_PlayerInput.GetButtonDown(m_Input.InputName);
In other classes, the same button works as expected.
In VirtualControlsManager.cs, I noticed the following:
C#:
public bool GetButton(string buttonName, InputBase.ButtonAction action)
{
var value = virtualControl.GetButton(action);
// value is always false
}
I've attached the full code of the ability below (with translated comments).
Any ideas why the input isn't coming through in this ability, or what I might be missing in the setup?
Thanks in advance!
C#:
protected override bool ValidateObject(GameObject obj, RaycastHit? raycastHit)
{
// First, check the base validation
if (!base.ValidateObject(obj, raycastHit))
{
// If the object has changed or is no longer valid, disable outline
if (m_IsHoveringValidObject)
{
DisableOutline();
CanDragItem?.Invoke(false);
m_IsHoveringValidObject = false;
m_LastValidObject = null;
}
return false;
}
// Check if the object has an Inventory component
var inventory = obj.GetComponent<Inventory>();
if (!inventory)
{
if (m_IsHoveringValidObject)
{
DisableOutline();
CanDragItem?.Invoke(false);
m_IsHoveringValidObject = false;
m_LastValidObject = null;
}
return false;
}
// If it's a new valid object or we're not currently hovering anything
if (!m_IsHoveringValidObject || m_LastValidObject != obj)
{
if (m_IsHoveringValidObject && m_LastValidObject != obj)
{
DisableOutline(); // Disable outline on previous object
}
EnableOutline(obj);
CanDragItem?.Invoke(true);
m_IsHoveringValidObject = true;
m_LastValidObject = obj;
if (m_DebugMode) {
Debug.Log($"[ItemDragAbility] Object validated: {obj.name}");
}
}
return true;
}
public override bool CanStartAbility()
{
// Check base conditions
if (!base.CanStartAbility()) {
return false;
}
// If already holding an item, only check input to release it
if (m_IsHolding) {
return m_Input.CheckInput(m_PlayerInput);
}
// Don't start the ability if an item is being returned
if (m_IsReturningItem) {
return false;
}
// Check if the Grab key was pressed and if there's a detected object
bool hasDetectedObject = m_DetectedObject;
return m_PlayerInput.GetButtonDown(m_Input.InputName) && hasDetectedObject;
}