Search Unity

Gameobject responds properly only when in inspector panel

Discussion in 'Editor & General Support' started by UnityHB, Mar 23, 2017.

  1. UnityHB

    UnityHB

    Joined:
    May 24, 2014
    Posts:
    20
    Im fairly new to Unity3d, I noted that certain parts of my code would not work. When i select the gameobject to view in the inspector panel the code works perfectly. Anyone come across this type of issue.
     
  2. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Is this code in a script that is running when not playing with the [ExecuteInEditMode] attribute?
     
  3. UnityHB

    UnityHB

    Joined:
    May 24, 2014
    Posts:
    20
    Yes it is I commented out [ExecuteInEditMode] but still have the issue
     
  4. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Yeah, I find that it only seems to run in edit mode when you have the object selected and it's in the inspector. It's not really the behaviour you'd expect. I find a using the OnDrawGizmos() function is more predictable and is run more frequently, that function is called once a frame when the scene window is rendered which is more like what you might want?
     
  5. UnityHB

    UnityHB

    Joined:
    May 24, 2014
    Posts:
    20
    if I comment out "//[ExecuteinEditMode]" shouldn't it allow objects to run in play mode
     
  6. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    [ExecuteinEditMode] only enables code to run in edit mode. It does not stop code running in play mode. So it should not make a difference to play mode at all if it's there or not.
     
  7. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    So your problem is that you have code you want to run in PlayMode but it's only running when you select an object. Is that object an instance in the scene? or is it a prefab in the project?
     
  8. UnityHB

    UnityHB

    Joined:
    May 24, 2014
    Posts:
    20
    Correct, instance of a scene
     
  9. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    What's the function that's not running? Start? Awake? Update? All of them?
     
  10. UnityHB

    UnityHB

    Joined:
    May 24, 2014
    Posts:
    20
    appears to be Update, it runs the first time and will not respond again until you click on object and display inspector
     
  11. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I don't know, sounds odd. Is the script being disabled or is the game object inactive?
     
  12. UnityHB

    UnityHB

    Joined:
    May 24, 2014
    Posts:
    20
    looks like it may be unity bug will download latest version