Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Object flashes on spawn

Discussion in 'Scripting' started by StarkIndustry, Dec 8, 2018.

  1. StarkIndustry

    StarkIndustry

    Joined:
    Dec 8, 2018
    Posts:
    1
    Hello,
    So i'm just spawning a projectile ready to be fired, and in game, the GameObject is instantly created but on screen, the model appears for 1frame, disapears, and then spawns a sec later. Quite annoying

    here is my script
    Code (CSharp):
    1. using System.Collections.Generic;
    2.  
    3. public class SpawnProjectile : MonoBehaviour {
    4.     public GameObject firepoint;
    5.     public GameObject vfx;
    6.  
    7.     private GameObject EffectToSpawn;
    8.  
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.        
    13.         EffectToSpawn = vfx;
    14.  
    15.  
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update () {
    20.         if(Input.GetMouseButtonDown(0)){
    21.             if(firepoint != null){
    22.                 vfx = (GameObject)Instantiate (EffectToSpawn, firepoint.transform.position,firepoint.transform.rotation);
    23.             }
    24.             else{
    25.                 Debug.Log ("no firepoint");
    26.             }
    27.         }
    28.  
    29.     }
    30.  
    31. }
    thank you
     
  2. II_Spoon_II

    II_Spoon_II

    Joined:
    Jun 16, 2018
    Posts:
    161
    Are you sure you are not destroying from another script?
     
  3. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    1,477
    This code is probably not the issue, is there other script at play here, perhaps on the effect itself?

    Also, why do you do the thing with vfx and EffectToSpawn?
    you can just instantiate the vfx variable.