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. Dismiss Notice

gameObject.active vs. gameObject.SetActive()

Discussion in 'Scripting' started by StarGamess, Jan 18, 2015.

  1. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    so what's the difference between these two? As far as i know they do the same don't they? I never though about it to much but a friend who just got into coding asked me this and i had no idea what to tell him.
     
  2. Dantus

    Dantus

    Joined:
    Oct 21, 2009
    Posts:
    5,667
    DonLoquacious likes this.
  3. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    SetActive, is what you want active will work in most cases but it is there for legacy reasons not go break old scripts. Some new features of unity 4.6 like canvas dont work properly with active and require SetActive()
     
  4. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    ohh thanks didn't know that ;p
     
  5. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    I'm changing the code as we speak but i ran into a problem how would i convert this

    bool inCombat = sword_Hand.active || bow_Hand.active || rifle_Hand.active || pistol_Hand.active;
     
  6. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The yellow warnings in the console should make you realise this.... :)
     
  7. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Also it mentions its depreciated in the docs as well as in the intellisense in vs has it flagged as such
     
  8. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Use activeSelf or activeInHierarchy depending on your needs.
     
  9. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    yupp thats what i thought i will change that tommorrow thanks for the help