Strange happenings Please help me understand

After hitting start game…

Console shows that Spawn gets called 4 times.
Notice how the numbers are in the console as well.

In this case I used the new Bow as default weapon (please note: looks good after placing in hand)
Unchecked isRightHanded…

Seems call one is good it shows false great
then it gets called again and is still false: notice the 2
then it gets called 3 and 4 both true…
box ends up in right hand upside down and not right…

I have been trying to find out where else on game start Spawn gets called and changes the bool on its own…

Here is a screen shot of Bow SO

and finally the code for Spawn is within this Weapon.cs below

using UnityEngine;

namespace RPG.Combat
{
    [CreateAssetMenu(fileName = "Weapon", menuName = "Weapons/Make New Weapon", order = 0)]
    public class Weapon : ScriptableObject 
    {
        [SerializeField] AnimatorOverrideController animatorOverride = null;
        [SerializeField] GameObject equippedPrefab = null;
        [SerializeField] float weaponRange = 2f;
        [SerializeField] float weaponDamage = 10f;
        [SerializeField] bool isRightHanded = true;

        int timesCalled = 0;

        public float GetWeaponRange()
        {
            return weaponRange;
        }

        public float GetWeaponDamage()
        {
            return weaponDamage;
        }        

        public void Spawn(Transform rightHand, Transform leftHand, Animator animator)
        {
            timesCalled += 1;
            Debug.Log(timesCalled + " Spawning... isRightHanded is: " + isRightHanded);
            if(equippedPrefab != null)
            {
                Transform handTranform;
                if(isRightHanded) 
                {
                    handTranform = rightHand;
                }
                else 
                {
                    handTranform = leftHand;
                }

                Instantiate(equippedPrefab, rightHand);
            }
            //Animator animator = GetComponent<Animator>();
            if(animatorOverride != null)
            {
                animator.runtimeAnimatorController = animatorOverride;   
            }
        }
    }

}

Thanks for any help!

Let’s make a tiny change to our Debug.Log… I’m curious to see the results here… if I’m right, I may have an idea what’s going on…

Debug.Log($"{animator.gameObject.name} Spawning {name}.  (times called = {timesCalled}) isRightHanded {isRightHanded}");

(By “little change” I mean let’s put in this complicated monstrousity full of data).
For more information on what I just did with the $"", see this topic at Microsoft on String Interpolation. Once you get used to it, you’ll never write another debug with "string "+value+“string” again.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms