Reload Drop Clip acts as inserted clip as well

Cheo

Active member
Hello, when working on my shotgun reloading today I stumbled upon a weird limitation of the Generic Reloader module - basically I was trying to make my character insert shotgun bullets one by one into the weapon, but realized that the only slot for the inserted prefab turns out to be Reload Drop Clip. Unless I'm mistaken, this prefab is meant to be used for both the dropped clip and the inserted one, and can't be used for the latter only, which doesn't make sense ! For example, just take the demo pistol and press pause when reloading, and you'll see that both the dropped and inserted clips are clones of the Pistol Clip prefab. We need two separate prefabs here. I would also suggest adding an inserted bullet prefab for the demo shotgun, this issue would have been spotted earlier had this been tried. Allow me to tag you @Sangemdoko as I believe you're in charge of the item module side. Thanks.
 
That is correct, I didn't think about adding two seperate prefabs for this.
I makes perfect sense... but unfortunatly after looking at the code the change isn't as simple as you might think. Additionaly it would break someones existing weapon if I made the change.

So I'll add it to the list of TODOs and add it in a future update.
In the meantime, you might want to look into making your own custom realoader script
 
Hi @Sangemdoko allow me to bump this thread, could this be looked at in the foreseeable future ? I tried making a custom reloader module a while ago but did not get perfect results. V2 already had a working shotgun reloading and it is something you'd expect from any shooter, so I don't think this is a niche request. Thanks.
 
I'm sorry this feature request got lost in the pile.
I will boost the priority of this task for you. I'll try to implement it in a way that doesn't break existing items.
Unfortunatly I can't give you an ETA yet. There are other tasks that are still higher priority.
I hope you understand
 
Looking at it again in more detail now. What do you mean about the shotgun not reloading properly in the demo scene?

For the shotgun, you reload it by spawning the projectile one by one. It's a similar technic to reloading arrows with a Bow:
1716545754746.png
This is were you define the prefab that gets spawned during reloading.

Then your shooter module can choose to fire using the projectile or using a hitscan
1716545843527.png
Check it out in the demo scene, it works as expected.

Now for the other thing you mentioned about the pistol clip needing two seperate prefabs.

In the serialize fields replace the drop field and add these fields:
Code:
[Tooltip("The prefab used when reloading.")]
[SerializeField] protected GameObject m_ReloadAddClipPrefab;
[FormerlySerializedAs("m_ReloadDropClip")]
[Tooltip("The prefab that is dropped when the character is reloading.")]
[SerializeField] protected GameObject m_ReloadDropClipPrefab;
Notice how I renamend ReloadDropClip to ReloadDropClipPrefab.


Here is the function you should change:

Code:
/// <summary>
/// Adds or removes the instantiated reloadable clip.
/// </summary>
/// <param name="add">Should the reloadable clip be instantiated?</param>
/// <param name="firstPerson">Is the first person perspective being affected?</param>
private void AddRemoveReloadableClip(bool add, bool firstPerson)
{
    var reloadClipPrefab = m_ReloadAddClipPrefab ?? m_ReloadDropClipPrefab;
    // If the perspective properties is null then that perspective isn't setup for the character.
    if (reloadClipPrefab == null) {
        return;
    }
    // If the clip can't be detached then the weapon's clip shouldn't be disabled.
    if (!m_ReloadDetachAttachClip) {
        return;
    }
    var reloadableClip = GetReloadableClip(firstPerson);
    if (reloadableClip == null) {
        return;
    }
    var reloadableClipAttachment = GetReloadableClipAttachment(firstPerson);
    if (add) {
        var clip = ObjectPoolBase.Instantiate(reloadClipPrefab, reloadableClip.position, reloadableClip.rotation);
        var remover = clip.GetCachedComponent<Remover>();
        if (remover != null) {
            remover.CancelRemoveEvent();
        }
        // The first person perspective requires the clip to be on the overlay layer so the fingers won't render in front of the clip.
        clip.transform.SetLayerRecursively(firstPerson ? LayerManager.Overlay : clip.layer);
        clip.transform.SetParentOrigin(reloadableClipAttachment);
        clip.transform.SetPositionAndRotation(reloadableClip.position, reloadableClip.rotation);
        if (firstPerson) {
            m_FirstPersonReloadAddClip = clip;
            m_FirstPersonReloadAddClip.SetActive(CharacterLocomotion.FirstPersonPerspective);
        } else {
            m_ThirdPersonReloadAddClip = clip;
            m_ThirdPersonReloadAddClip.SetActive(!CharacterLocomotion.FirstPersonPerspective);
        }
    } else {
        var clip = firstPerson ? m_FirstPersonReloadAddClip : m_ThirdPersonReloadAddClip;
        if (clip != null) {
            ObjectPoolBase.Destroy(clip);
            if (firstPerson) {
                m_FirstPersonReloadAddClip = null;
            } else {
                m_ThirdPersonReloadAddClip = null;
            }
        }
        reloadableClip.gameObject.SetActive(true);
    }
}

Add that should do the trick for your pistol if you need a different prefab for attaching the clip and dropping it :)
 
Hi, I must say I'm confused about the shotgun which indeed does reload correctly in the demo scene, I don't know what happened šŸ˜“. I'm a bit surprised by the Spawn Projectile module being used for that purpose but if it works then that's totally fine - speaking of which, allow me to share this fixed SDASS shotgun reloading !


"Prefab" just needs to be added at the end of m_ReloadDropClip in a few other places and we also need to add :

C#:
        public GameObject ReloadAddClipPrefab { get { return m_ReloadAddClipPrefab; } set { m_ReloadAddClipPrefab = value; } }
        public GameObject ReloadDropClipPrefab { get { return m_ReloadDropClipPrefab; } set { m_ReloadDropClipPrefab = value; } }

But once that is done everything works perfectly ! Thank you very much Santiago !
 
Top