Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug Instantiated point light crashing game when built

Discussion in 'Editor & General Support' started by sinxoxo, Feb 22, 2024.

  1. sinxoxo

    sinxoxo

    Joined:
    Aug 3, 2022
    Posts:
    4
    made a video to show the problem and the instantiate code is below that

    Code (CSharp):
    1. public void CastSpell()
    2.     {
    3.         EnableMagicSigil();
    4.         playerManager.playerStats.TakeManaDamage(currentSpell.manaCost);
    5.  
    6.         //spell doesnt hold
    7.         if (!currentSpell.spellHolds)
    8.         {
    9.             Ray ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
    10.             RaycastHit hit;
    11.  
    12.             if (Physics.Raycast(ray, out hit))
    13.                 destination = hit.point;
    14.             else
    15.             {
    16.                 //default value was just 1000 set back to that if infinity causes problems
    17.                 destination = ray.GetPoint(Mathf.Infinity);
    18.             }
    19.  
    20.             InstantiateProjectile();
    21.         }
    22.         else if (currentSpell.spellHolds)
    23.         {
    24.             var projectileObj = Instantiate(currentSpell.spellProjectileVFX, playerManager.leftHandSpellSpawnPoint.position, playerManager.transform.rotation) as GameObject;
    25.         }
    26.     }
    27.  
    28.     private void InstantiateProjectile()
    29.     {
    30.         var projectileObj = Instantiate(currentSpell.spellProjectileVFX, playerManager.leftHandSpellSpawnPoint.position, playerManager.transform.rotation) as GameObject;
    31.         projectileObj.GetComponent<Rigidbody>().velocity = (destination - playerManager.leftHandSpellSpawnPoint.position)
    32.         .normalized * currentSpell.spellSpeed;
    33.     }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,053
    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?
     
  3. sinxoxo

    sinxoxo

    Joined:
    Aug 3, 2022
    Posts:
    4
    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
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,053
    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.
     
  5. sinxoxo

    sinxoxo

    Joined:
    Aug 3, 2022
    Posts:
    4
    sure thing thanks :)