Hey, I've tried a ton of things so the code may look a bit weird by now, but basically I've been trying to work on a speed potion.
The speed potion would access its stats through the attributes and thus apply them to a method in the userstatemanager script.
The code currently for the speed potion is as follows:
Method in the userstatemanager is :
Related attributes on the item: http://prntscr.com/1qi1xdg
Weirdly enough it works in editor playtime, however when in build, I unfortunately get this error:
I am kind of lost where it's going wrong. Help would be very much appreciated. ?
The speed potion would access its stats through the attributes and thus apply them to a method in the userstatemanager script.
The code currently for the speed potion is as follows:
C#:
namespace Opsive.UltimateInventorySystem.ItemObjectBehaviours
{
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateInventorySystem.Core;
using Opsive.UltimateInventorySystem.ItemActions;
using PixelCrushers.DialogueSystem;
using Language.Lua;
using Opsive.UltimateInventorySystem.Core.DataStructures;
using Opsive.UltimateInventorySystem.Core.AttributeSystem;
public class SpeedPotion : ItemAction
{
public float speedUpTimer;
public string spellEffect;
public string alertString;
public UserStateManager userStateManager;
protected override bool CanInvokeInternal(ItemInfo iteminfo, ItemUser itemUser)
{
return true;
}
protected override void InvokeActionInternal(ItemInfo itemInfo, ItemUser itemUser)
{
//var managerAttribute = itemInfo.Item.GetAttribute<Attribute<UserStateManager>>("StateManager");
//managerAttribute.SetOverrideValue(GameObject.Find("UserStateManager").GetComponent<UserStateManager>());
//userStateManager = managerAttribute.GetValue();
userStateManager = GameObject.Find("UserStateManager").GetComponent<UserStateManager>();
if (itemInfo.Item.GetAttribute<Attribute<float>>("speedUpTimer") != null)
{
var attribute = itemInfo.Item.GetAttribute<Attribute<float>>("speedUpTimer");
speedUpTimer = attribute.GetValue();
}
if (itemInfo.Item.GetAttribute<Attribute<string>>("spellEffect") != null)
{
var effectAttribute = itemInfo.Item.GetAttribute<Attribute<string>>("spellEffect");
spellEffect = effectAttribute.GetValue();
}
if (itemInfo.Item.GetAttribute<Attribute<string>>("alertString") != null)
{
var alertAttribute = itemInfo.Item.GetAttribute<Attribute<string>>("alertString");
alertString = alertAttribute.GetValue();
}
userStateManager.speedTimer = speedUpTimer;
userStateManager.ApplySpellEffect(spellEffect);
DialogueManager.ShowAlert(alertString, 4f);
}
}
}
Method in the userstatemanager is :
Code:
public void ApplySpellEffect(string spellEffect)
{
var characterLocomotion = cache.playerObject.GetComponent<UltimateCharacterLocomotion>();
var slow75Ability = characterLocomotion.GetAbility<SpeedChange>(6);
var speed15Ability = characterLocomotion.GetAbility<SpeedChange>(7);
switch (spellEffect)
{
case "Slow75":
if (!isSlowed)
{
Timing.RunCoroutine(_slowTimerStart());
characterLocomotion.TryStartAbility(slow75Ability);
audiosource.PlayOneShot(slowDebuffSound);
}
break;
case "Speed15":
Timing.RunCoroutine(_speedTimerStart());
characterLocomotion.TryStartAbility(speed15Ability);
audiosource.PlayOneShot(slowDebuffSound);
break;
default:
break;
}
}
Related attributes on the item: http://prntscr.com/1qi1xdg
Weirdly enough it works in editor playtime, however when in build, I unfortunately get this error:
NullReferenceException: Object reference not set to an instance of an object
at UserStateManager.ApplySpellEffect (System.String spellEffect) [0x00094] in H:\PolygonNew\Assets\UserStateManager.cs:121
at Opsive.UltimateInventorySystem.ItemObjectBehaviours.SpeedPotion.InvokeActionInternal (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.ItemActions.ItemUser itemUser) [0x000df] in H:\PolygonNew\Assets\Scripts\InventoryItems\SpeedPotion.cs:48
at Opsive.UltimateInventorySystem.ItemActions.ItemAction.InvokeAction (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.ItemActions.ItemUser itemUser) [0x0003d] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\ItemActions\ItemAction.cs:97
at Opsive.UltimateInventorySystem.ItemActions.UseItemActionSetAttribute.InvokeActionInternal (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.ItemActions.ItemUser itemUser) [0x00037] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\ItemActions\UseItemActionSetAttribute.cs:76
at Opsive.UltimateInventorySystem.ItemActions.ItemAction.InvokeAction (Opsive.UltimateInventorySystem.Core.DataStructures.ItemInfo itemInfo, Opsive.UltimateInventorySystem.ItemActions.ItemUser itemUser) [0x0003d] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\ItemActions\ItemAction.cs:97
at Opsive.UltimateInventorySystem.UI.Panels.ActionPanels.ItemActionPanel.InvokeActionInternal (System.Int32 index) [0x0000e] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\UI\Panels\ActionPanels\ItemActionPanel.cs:66
at Opsive.UltimateInventorySystem.UI.Panels.ActionPanels.ActionPanel`1[T].InvokeAction (System.Int32 index) [0x00009] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\UI\Panels\ActionPanels\ActionPanel.cs:119
at Opsive.UltimateInventorySystem.UI.Panels.ActionPanels.ActionPanel`1+<>c__DisplayClass13_0[T].<OpenInternal>b__0 () [0x00000] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\UI\Panels\ActionPanels\ActionPanel.cs:69
at Opsive.UltimateInventorySystem.UI.CompoundElements.ActionButton.Press () [0x0005a] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\UI\CompoundElements\ActionButton.cs:72
at Opsive.UltimateInventorySystem.UI.CompoundElements.ActionButton.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00011] in H:\PolygonNew\Assets\Opsive\UltimateInventorySystem\Scripts\UI\CompoundElements\ActionButton.cs:123
at UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00001] in C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\ExecuteEvents.cs:50
at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00074] in C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\ExecuteEvents.cs:262
UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
UnityEngine.DebugLogHandler:LogException(Exception, Object)
UnityEngine.Logger:LogException(Exception, Object)
UnityEngine.Debug:LogException(Exception)
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1) (at C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\ExecuteEvents.cs:266)
UnityEngine.EventSystems.StandaloneInputModule:ReleaseMouse(PointerEventData, GameObject) (at C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:187)
UnityEngine.EventSystems.StandaloneInputModulerocessMousePress(MouseButtonEventData) (at C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:642)
UnityEngine.EventSystems.StandaloneInputModulerocessMouseEvent(Int32) (at C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:548)
UnityEngine.EventSystems.StandaloneInputModulerocessMouseEvent() (at C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:528)
UnityEngine.EventSystems.StandaloneInputModulerocess() (at C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\InputModules\StandaloneInputModule.cs:282)
UnityEngine.EventSystems.EventSystem:Update() (at C:\Program Files\Unity\Hub\Editor\2020.3.4f1\Editor\Data\Resources\PackageManager\BuiltInPackages\com.unity.ugui\Runtime\EventSystem\EventSystem.cs:385)
I am kind of lost where it's going wrong. Help would be very much appreciated. ?