Hey, I'm trying to make two custom actions for Adventure Creator that tell UCC to either equip or unequip my melee weapon. I'm using the third person Opsive package. I have the weapon set to be equipped by UCC by default, that's all working as intended with attack animations etc all fine.
So, as for the custom AC actions, they are triggering fine, the weapon disappears and reappears and the player changes stance between the one for holding a melee item and one without. However I'm having some weird results with the players arms after having run either action, seems something is going wrong with the IK, they are sort of moving about further from the characters waist then normal and twist around the character when turning.
I'm guessing the code I'm using isn't telling UCC everything it needs to control stuff like the IK correctly. I've posted the two (mostly identical) scripts below but the only UCC commands I'm using really are:
inventory.AddItem(item, true, true);
inventory.EquipItem(m_ItemType, m_SlotID, true);
and then for the unequip:
inventory.RemoveItem(m_ItemType, i, 1, false);
inventory.UnequipItem(m_SlotID);
Any help would be greatly appreciated.
Here are the scripts in full (you can ignore the removeAll part):
So, as for the custom AC actions, they are triggering fine, the weapon disappears and reappears and the player changes stance between the one for holding a melee item and one without. However I'm having some weird results with the players arms after having run either action, seems something is going wrong with the IK, they are sort of moving about further from the characters waist then normal and twist around the character when turning.
I'm guessing the code I'm using isn't telling UCC everything it needs to control stuff like the IK correctly. I've posted the two (mostly identical) scripts below but the only UCC commands I'm using really are:
inventory.AddItem(item, true, true);
inventory.EquipItem(m_ItemType, m_SlotID, true);
and then for the unequip:
inventory.RemoveItem(m_ItemType, i, 1, false);
inventory.UnequipItem(m_SlotID);
Any help would be greatly appreciated.
Here are the scripts in full (you can ignore the removeAll part):
C#:
using UnityEngine;
using System.Collections.Generic;
using Opsive.UltimateCharacterController.Inventory;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionEquipWeapon : Action
{
[Tooltip("The character that should drop the item.")]
[SerializeField] protected GameObject m_Character;
[Tooltip("The ItemType that the character should remove.")]
[SerializeField] protected ItemType m_ItemType;
[Tooltip("The Slot that the character should Unequip.")]
[SerializeField] protected int m_SlotID;
[SerializeField] private bool isPlayer;
[SerializeField] public bool removeAll;
public ActionEquipWeapon()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Equip Weapon";
description = "Equip a weapon added to the itemset";
}
public override float Run()
{
if (isPlayer)
{
m_Character = AC.KickStarter.player.gameObject;
}
var inventory = m_Character.GetComponent<InventoryBase>();
// A single ItemType can exist in multiple slots. Drop all of the items.
if (removeAll)
{
inventory.UnequipItem(m_SlotID);
inventory.RemoveAllItems(false);
}
else
for (int i = 0; i < inventory.SlotCount; ++i)
{
var item = inventory.GetItem(m_ItemType, i);
if (item != null)
{
//inventory.AddItem(item, true, true);
inventory.EquipItem(m_ItemType, m_SlotID, true);
}
}
if (!isRunning)
{
isRunning = true;
return defaultPauseTime;
}
else
{
isRunning = false;
return 0f;
}
}
public override void Skip()
{
Run();
}
#if UNITY_EDITOR
public override void ShowGUI()
{
isPlayer = EditorGUILayout.Toggle("Is Player?", isPlayer);
if (!isPlayer)
m_Character = (GameObject)EditorGUILayout.ObjectField("Character:", m_Character, typeof(GameObject), true);
removeAll = EditorGUILayout.Toggle("Remove All Items?", removeAll);
if (!removeAll)
m_ItemType = (ItemType)EditorGUILayout.ObjectField("Item Type to remove", m_ItemType, typeof(ItemType), true);
m_SlotID = (int)EditorGUILayout.IntField("Slot ID:", m_SlotID);
AfterRunningOption();
}
public override string SetLabel()
{
return string.Empty;
}
#endif
}
}
C#:
using UnityEngine;
using System.Collections.Generic;
using Opsive.UltimateCharacterController.Inventory;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{
[System.Serializable]
public class ActionUnequipWeapon : Action
{
[Tooltip("The character that should drop the item.")]
[SerializeField] protected GameObject m_Character;
[Tooltip("The ItemType that the character should remove.")]
[SerializeField] protected ItemType m_ItemType;
[Tooltip("The Slot that the character should Unequip.")]
[SerializeField] protected int m_SlotID;
[SerializeField] private bool isPlayer;
[SerializeField] public bool removeAll;
public ActionUnequipWeapon()
{
this.isDisplayed = true;
category = ActionCategory.Custom;
title = "Unequip Weapon";
description = "Unequip a weapon added to the itemset";
}
public override float Run()
{
if (isPlayer)
{
m_Character = AC.KickStarter.player.gameObject;
}
var inventory = m_Character.GetComponent<InventoryBase>();
// A single ItemType can exist in multiple slots. Drop all of the items.
if (removeAll)
{
inventory.UnequipItem(m_SlotID);
inventory.RemoveAllItems(false);
}
else
for (int i = 0; i < inventory.SlotCount; ++i)
{
var item = inventory.GetItem(m_ItemType, i);
if (item != null)
{
//inventory.RemoveItem(m_ItemType, i, 1, false);
inventory.UnequipItem(m_SlotID);
}
}
if (!isRunning)
{
isRunning = true;
return defaultPauseTime;
}
else
{
isRunning = false;
return 0f;
}
}
public override void Skip()
{
Run();
}
#if UNITY_EDITOR
public override void ShowGUI()
{
isPlayer = EditorGUILayout.Toggle("Is Player?", isPlayer);
if (!isPlayer)
m_Character = (GameObject)EditorGUILayout.ObjectField("Character:", m_Character, typeof(GameObject), true);
removeAll = EditorGUILayout.Toggle("Remove All Items?", removeAll);
if (!removeAll)
m_ItemType = (ItemType)EditorGUILayout.ObjectField("Item Type to remove", m_ItemType, typeof(ItemType), true);
m_SlotID = (int)EditorGUILayout.IntField("Slot ID:", m_SlotID);
AfterRunningOption();
}
public override string SetLabel()
{
return string.Empty;
}
#endif
}
}
Last edited: