Instantiated point light crashing game when built

made a video to show the problem and the instantiate code is below that

public void CastSpell()
    {
        EnableMagicSigil();
        playerManager.playerStats.TakeManaDamage(currentSpell.manaCost);

        //spell doesnt hold
        if (!currentSpell.spellHolds)
        {
            Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
                destination = hit.point;
            else
            {
                //default value was just 1000 set back to that if infinity causes problems
                destination = ray.GetPoint(Mathf.Infinity);
            }

            InstantiateProjectile();
        }
        else if (currentSpell.spellHolds)
        {
            var projectileObj = Instantiate(currentSpell.spellProjectileVFX, playerManager.leftHandSpellSpawnPoint.position, playerManager.transform.rotation) as GameObject;
        }
    }

    private void InstantiateProjectile()
    {
        var projectileObj = Instantiate(currentSpell.spellProjectileVFX, playerManager.leftHandSpellSpawnPoint.position, playerManager.transform.rotation) as GameObject;
        projectileObj.GetComponent<Rigidbody>().velocity = (destination - playerManager.leftHandSpellSpawnPoint.position)
        .normalized * currentSpell.spellSpeed;
    }

First let me just say that I want to loot your dungeon… it looks great!!

Second, are you getting any errors in the runtime log?? It sounds like at least the sound thread and other engine core stuff is still running.

What about trying to rebuild all your lighting? Or just a reimport-all and then a rebuild?

hey thanks for the reply and compliment! ill look into everything you said and let you know how it goes, im new to unity and programming in general so might take a minute lol

I would actually recommend just doing 1000, or some other big number such as your camera far clip distance.

Mathf.Infinity might leak into something else or cause other “data poisoning” issues, kinda the same way that NaNs might.

sure thing thanks :slight_smile: