Search Unity

  1. Unity 2018.3 is now released.
    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. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. 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:
    147
    Are you sure you are not destroying from another script?
     
  3. SparrowsNest

    SparrowsNest

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