Bullet prefab not instantiating in bullet spawner like it should

Hey, so I have a script on my player object which is supposed to instantiate a “bullet” prefab GameObject at the player in the direction of the targetPoint.

The issue I’m having is that there just is no GameObject instantiated that I can tell. Nothing appears in the Hierarchy or the scene. I am certain that the code is spectacular as well as the setup in unity. I don’t believe I did anything drastic to interfere with my weapon.cs or bullet.cs. I only added basic propulsion parameter over @ fpscontroller.cs after sorting the weapon and bullet as well as the impact effects.

The instantiation did work at one point perfectly, now it mysteriously doesn’t didn’t touch anything as it was perfect.

Bullet.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bullet : MonoBehaviour
{
    private void OnCollisionEnter(Collision ObjectHit)
    {
        if (ObjectHit.gameObject.CompareTag("Target"))
        {
            print("hit " + ObjectHit.gameObject.name + " !");
            
            CreateBulletImpactEffect(ObjectHit);
            
            Destroy(gameObject);
        }
    
        if (ObjectHit.gameObject.CompareTag("Metal/Wall"))
        {
             print("Hit the wall");
            
            CreateBulletImpactEffect(ObjectHit);
        }
    
 
        if (ObjectHit.gameObject.CompareTag("Metal/Floor"))
        {
            print("Hit the ground");
            
            CreateBulletImpactEffect(ObjectHit);
        }
    }


    void CreateBulletImpactEffect(Collision ObjectHit)
    {
        ContactPoint contact = ObjectHit.contacts[0];

        GameObject ImpactVfx = Instantiate(GlobalReferences.Instance.BulletImpactEffectPrefab,
        contact.point, Quaternion.LookRotation(contact.normal)
        );

        ImpactVfx.transform.SetParent(ObjectHit.gameObject.transform);
    }
}

Weapon.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Weapon : MonoBehaviour
{
    
    public bool isShooting, readyToShoot;
    bool allowReset = true;

    [Header("Bullet Parameters")]
    public GameObject bulletPrefab;
    public Transform bulletSpawn;
    public float bulletVelocity = 30.0f;
    public float bulletPrefabLifeTime = 3f;
    
    [Header("Shooting Parameters")]
    public float shootingDelay =2.0F;
    //Burstfire
    public int bulletPerBurst = 3;
    public int burstBulletsLeft;
    //Spread
    public float spreadIntensity;

    
      [Header("Reloading Parameters")]
      public float reloadTime;
      public int capacity, energyLeft;
      public bool isReloading;


    private Animator animator;
    

    public enum ShootingMode

    {
        SemiAuto,
        Burst,
        Auto, 
    }

    public ShootingMode currentShootingMode;

    private void Awake()
    {
        readyToShoot = true;
        burstBulletsLeft = bulletPerBurst;
        animator = GetComponent<Animator>();

        energyLeft = capacity;
    }
    

         // Update is called once per frame
    void Update()
    {
       if (currentShootingMode == ShootingMode.Auto)
       {
        isShooting = Input.GetKey(KeyCode.Mouse0);
       }
       else if (currentShootingMode == ShootingMode.SemiAuto || currentShootingMode == ShootingMode.Burst)
       {
         isShooting = Input.GetKeyDown(KeyCode.Mouse0);
       }

       if (Input.GetKeyDown(KeyCode.R) && energyLeft < capacity && isReloading == false)
       {
        Reload();
       }

       if (readyToShoot && !isShooting && energyLeft < 0 && !isReloading)
       {
        Reload();
       }

       if (readyToShoot && isShooting)
       {
         burstBulletsLeft = bulletPerBurst;
         FireWeapon();
       }


    }

    private void FireWeapon()
    {
        energyLeft--;


        animator.SetTrigger("Recoil");

        VXSentinal.Instance.shootingSoundVX.Play();


        readyToShoot = false;

        Vector3 shootingDirection = CalculateDirectionAndSpread().normalized;


        GameObject bullet = Instantiate(bulletPrefab, bulletSpawn.position, Quaternion.identity);
        
        bullet.transform.forward = shootingDirection;
        
        bullet.GetComponent<Rigidbody>().AddForce(shootingDirection * bulletVelocity, ForceMode.Impulse);
        
        
        StartCoroutine(DestroyBulletAfterSomeTime(bullet, bulletPrefabLifeTime));

        // Check if we are done shooting
        if (allowReset)
        {
            Invoke("ResetShot", shootingDelay);
            allowReset = false;
        }

        // For burst fire
        if (currentShootingMode == ShootingMode.Burst && burstBulletsLeft > 1)
        {
            burstBulletsLeft--; 
            Invoke("FireWeapon", shootingDelay);
        }



    }

     private void Reload()
     {
        isReloading = true;
        Invoke("ReloadCompleted", reloadTime);
     }

     private void ReloadCompleted()
     {
        energyLeft = capacity;
        isReloading = false;
     }


    private void ResetShot()
    {
        readyToShoot = true;
        allowReset = true;
    }

    public Vector3 CalculateDirectionAndSpread() 
    {
        Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
        RaycastHit hit;

        Vector3 targetPoint;
        if (Physics.Raycast(ray, out hit))
        {
            targetPoint = hit.point;
        }
        else
        {
            targetPoint = ray.GetPoint(100);
        }

        Vector3 direction = targetPoint - bulletSpawn.position;

        float x = UnityEngine.Random.Range(-spreadIntensity, spreadIntensity);
        float y = UnityEngine.Random.Range(-spreadIntensity, spreadIntensity);

        return direction + new Vector3(x, y, 0);

    }
    
    private IEnumerator DestroyBulletAfterSomeTime(GameObject bullet, float delay)
    {
        yield return new WaitForSeconds(delay);
        Destroy(bullet);
    }


}

BulletImpactEffect.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BulletImpactEffect : MonoBehaviour
{
    public float bulletImpactPrefabLifetime = 3f;
    public AudioClip[] impactSounds;

    private AudioSource audioSource;

    // Start is called before the first frame update
    void Start()
    {
        audioSource = GetComponent<AudioSource>();
        StartCoroutine(DestroyAfterLifetime());
        PlayRandomImpactSound(); // Call the random impact sound method
    }

    private IEnumerator DestroyAfterLifetime()
    {
        yield return new WaitForSeconds(bulletImpactPrefabLifetime);
        Destroy(gameObject);
    }

    private void PlayRandomImpactSound()
    {
        if (impactSounds.Length == 6)
        {
            Debug.LogWarning("No impact sounds assigned.");
            return;
        }

        int randomIndex = Random.Range(0, impactSounds.Length);
        audioSource.clip = impactSounds[randomIndex];
        audioSource.Play();
    }
}

Look, I’ve decided to move on with the project and deal with it later. I got a few tricks up my sleeve but it involves creating new gun scripts and a project (push comes to shove).

honestly I am angry inside and restless just thinking what did i even do? it was working, now its not. haven’t touched or fiddled with any of the scripts after the successful testing.

I would really appreciate your time and insight on what might be the issue

Seth.

You have ticking time bomb: you have a lot of public variables in your scripts which have values assigned. This is dangerous as Unity may overwrite these values (i.e. bulletPrefabLifeTime). Either declare them private and set them in code, or only set the values in the inspector or prefab. You have a bullet destroying itself on OnCollisionEnter. Are you sure it isn't being destroyed as soon as it's created?