Hi together,
after implementing the LazyValue I get this error of StackOverflow and I can’t find why this is happening.
StackOverflowException: The requested operation caused a stack overflow. UnityEngine.Transform.Find (System.String n) (at <9baebf9af86541678fd15bfdbf5f26eb>:0) RPG.Combat.Weapon.DestroyOldWeapon (UnityEngine.Transform rightHand, UnityEngine.Transform leftHand) (at Assets/Game/Scripts/Combat/Weapon.cs:39) RPG.Combat.Weapon.Spawn (UnityEngine.Transform rightHand, UnityEngine.Transform leftHand, UnityEngine.Animator anim) (at Assets/Game/Scripts/Combat/Weapon.cs:21) RPG.Combat.Fighter.AttachWeapon (RPG.Combat.Weapon weapon) (at Assets/Game/Scripts/Combat/Fighter.cs:176) RPG.Combat.Fighter.SetupDefaultWeapon () (at Assets/Game/Scripts/Combat/Fighter.cs:45) GameDevTV.Utils.LazyValue1[T].ForceInit () (at Assets/Game/Scripts/Utils/LazyValue.cs:56) GameDevTV.Utils.LazyValue1[T].get_value () (at Assets/Game/Scripts/Utils/LazyValue.cs:38) RPG.Combat.Fighter+<GetAdditiveModifiers>d__30.MoveNext () (at Assets/Game/Scripts/Combat/Fighter.cs:144) RPG.Stats.BaseStats.GetAdditiveModifier (RPG.Stats.Stat stat) (at Assets/Game/Scripts/Stats/BaseStats.cs:78) RPG.Stats.BaseStats.GetStat (RPG.Stats.Stat stat) (at Assets/Game/Scripts/Stats/BaseStats.cs:65) RPG.Combat.Fighter.AttachWeapon (RPG.Combat.Weapon weapon) (at Assets/Game/Scripts/Combat/Fighter.cs:177) RPG.Combat.Fighter.SetupDefaultWeapon () (at Assets/Game/Scripts/Combat/Fighter.cs:45) GameDevTV.Utils.LazyValue1[T].ForceInit () (at Assets/Game/Scripts/Utils/LazyValue.cs:56) GameDevTV.Utils.LazyValue1[T].get_value () (at Assets/Game/Scripts/Utils/LazyValue.cs:38) RPG.Combat.Fighter+<GetAdditiveModifiers>d__30.MoveNext () (at Assets/Game/Scripts/Combat/Fighter.cs:144) RPG.Stats.BaseStats.GetAdditiveModifier (RPG.Stats.Stat stat) (at Assets/Game/Scripts/Stats/BaseStats.cs:78) RPG.Stats.BaseStats.GetStat (RPG.Stats.Stat stat) (at Assets/Game/Scripts/Stats/BaseStats.cs:65) RPG.Combat.Fighter.AttachWeapon (RPG.Combat.Weapon weapon) (at Assets/Game/Scripts/Combat/Fighter.cs:177)
…
and so on… the game is running but this error drives me mad.
I’ve also implemented a bool to protect the AttachWeapon method to be executed, but unity seems to be not very interested about the bool
public void EquipWeapon(Weapon weapon)
{
if (weaponEquipped != true)
{
currentWeapon.value = weapon;
AttachWeapon(weapon);
}
}
public bool IsWeaponEquipped()
{
return weaponEquipped;
}
public bool UnEquippWeapon()
{
weaponEquipped = false;
return weaponEquipped;
}
private void AttachWeapon(Weapon weapon)
{
if (weaponEquipped != true)
{
weapon.Spawn(rightHandTranfsorm, leftHandTranfsorm, anim);
weaponDamage = basestat.GetStat(Stat.Damage);
weaponRange = weapon.GetWeaponRange();
}
}
the bool is initialised as false and is resettet by the weaponpickUp…
Any suggestions?
Greetz Umoy