Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why is Start() behave like Update()

Discussion in 'Scripting' started by pKallv, Sep 29, 2015.

  1. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,129
    Just about to do some testing with RigidBody2D and started by adding below code. What it does is that it loops, as Update(), and add an infinitive number of the GameObject. Can someone please explain why as i thought it should only execute this code once?

    If I only have a print it execute only once but with the GameObject it loops.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class myScript : MonoBehaviour {
    5.  
    6.     void Start() {
    7.  
    8.         GameObject myGameObject = Resources.Load ("Ruby") as GameObject;
    9.         Instantiate (myGameObject);
    10.  
    11.     }
    12.  
    13. }
     
    Last edited: Sep 29, 2015
  2. MrPriest

    MrPriest

    Joined:
    Mar 17, 2014
    Posts:
    202
    It should run only once, unless it instantiates itself, I guess.
    Does this "Ruby" have this script in it?
     
  3. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,129
    Oh my god, for some reason i had added the script to the Ruby as you stated as well as to the empty GameObject i use to execute. I didn't even consider that. What a stupid mistake, I should have checked that. Thanks!
     
    LaneFox likes this.
  4. MrPriest

    MrPriest

    Joined:
    Mar 17, 2014
    Posts:
    202
    Sure, glad to have helped.