Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    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:
    156
    Are you sure you are not destroying from another script?
     
  3. SparrowsNest

    SparrowsNest

    Joined:
    Apr 6, 2017
    Posts:
    1,167
    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.