Search Unity

Update() not called in GameObject's instantiated from GameObject

Discussion in 'Editor & General Support' started by thpetsen, Oct 3, 2010.

  1. thpetsen

    thpetsen

    Joined:
    Feb 25, 2010
    Posts:
    21
    Hi when upgrading a project from 2.6 to 3.0 I noticed that Update() no longer gets called in several of my GameObjects. These were instantiated from an existing GameObject in the scene.

    One solution is to convert the GameObject in question into a prefab and instantiate the prefab, this works both in 2.6 and 3.

    I think this should have been mentioned in the release note. According to documentation the Update() function should be called, no matter how the object was created. A warning would have helped. Luckily I have seen something similar before ...

    Cheers,
    /Thomas
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The Update function is always called, nothing changed, so there's nothing to mention in the release notes about that. The only way it's not called is if the script is inactive.

    --Eric
     
  3. thpetsen

    thpetsen

    Joined:
    Feb 25, 2010
    Posts:
    21
    You are exactly right - the script is actually disabled in the instantiated objects. So the issue is not why Update() is not called, but why Unity() handles components differently when instantiating from prefab or from GameObject. Prefab-instantiated GameObjects have the component active, GameObject-instantiated GameObjects has the component inactive - same code.
    Cheers !
    /Thomas
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Instantiated objects are always active, regardless of whether they're instantiated from a prefab or from an object in the scene. You can set them to inactive by script after instantiating.

    --Eric