[Solved] bow placment in wrong hand

I found my bug…


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

                **Instantiate(equippedPrefab, handTransform);** -- was passingrighthand here
            }
            //Animator animator = GetComponent<Animator>();
            if(animatorOverride != null)
            {
                animator.runtimeAnimatorController = animatorOverride;   
            }
        }type or paste code here

Still curious about the 4 calls when game loads tho…

Did you try my Debug from the other topic? I’m still curious about the extra calls too.

Hello Brian

Here is the screen shot:

Is this the right one?

Still curious how these start up at start up, lol seems like a funny order.
Every character that has a weapon gets called right? and every character has a weapon even it it is unarmed. Seems that means 1 call each NOT 2… on the first

In this scene I only had Player and Enemy (1)
Screen shot happens just after start up before any movement.

AM I seeing things? lol

Thanks

Here is that Spawn procedure.

        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);
            Debug.Log($"{animator.gameObject.name} Spawning {name}.  (times called = {timesCalled}) isRightHanded {isRightHanded}");

            DestroyOldWeapon(rightHand, leftHand);
            if(equippedPrefab != null)
            {
                Transform handTransform = GetTransform(rightHand, leftHand);

                GameObject weapon = Instantiate(equippedPrefab, handTransform);
                weapon.name = weaponName;
            }
            //Animator animator = GetComponent<Animator>();
            if(animatorOverride != null)
            {
                animator.runtimeAnimatorController = animatorOverride;   
            }
        }

And the current at start screen shot…
NOTICE how big timesCalled is at start… why?

Notice also I have added a couple of characters and From what I notice Each character gets called twice. right? again no movement just pressed start. then screen shot console.

Any idea why the two calls for each?

Thanks

As I suspected, it’s getting called a lot because each character Equips the Default Weapon on Awake (the first time you run the game) and then when LoadLastScene() is called (reloads the scene whether or not there is a save file), the scene is reloaded and it’s called again… if you have a save file, it might be called a 3rd time.
Because it’s a Scriptable Object, it’s serializing that time used… so every character that loads a bow, adds one to the total, and that will cary on as you play again and again
Since the Bow1 and Unarmored are different SOs, they get different serials.

Privacy & Terms