AttachClip error message

Zaddo

Active member
1. Character controller variant:
Ultimate Character Controller

2. Unity version:
2020.2.1f1 URP

3. Bug description
Suggest change to the ShootableWeapon script in the AttachClip method. If there is no clip gameobject defined, the AddRemoveReloadableClip will throw an error. Could a check be added if m_ReloadDropClip is null, like the code does in ReloadItem. example script below.

4. Steps to reproduce
On a shootable weapon, have no clip object, but have the Reload Detach Attach Clip checkbox checked.

5. The full error message (if any)

PS. Sorry, should be in General.

Code:
        private void AttachClip()
        {
            if (!m_Reloading) {
                return;
            }

            // Attach the clip back to the original transform. Attach both first and third person in case there is a perspective switch.
#if FIRST_PERSON_CONTROLLER
            DetachAttachClip(false, m_FirstPersonPerspectiveProperties as IShootableWeaponPerspectiveProperties, true);
            if (m_ReloadDropClip != null)
                AddRemoveReloadableClip(false, m_FirstPersonPerspectiveProperties as IShootableWeaponPerspectiveProperties, true);
#endif
            DetachAttachClip(false, m_ThirdPersonPerspectiveProperties as IShootableWeaponPerspectiveProperties, false);
            if (m_ReloadDropClip != null)
                AddRemoveReloadableClip(false, m_ThirdPersonPerspectiveProperties as IShootableWeaponPerspectiveProperties, false);

            // Clean up from the event.
            if (m_ReloadDetachAttachClipEvent != null) {
                Scheduler.Cancel(m_ReloadDetachAttachClipEvent);
                m_ReloadDetachAttachClipEvent = null;
            }
        }
 
Last edited:
Top