Search Unity

non-enabled scripts are receiving SendMessage ?

Discussion in 'Editor & General Support' started by Tom163, Jul 25, 2010.

  1. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,290
    Is it intentional behaviour that scripts, even if they are not enabled (in the inspector, or via component.enabled = false) are receiving and reacting to SendMessage() ?


    I have this odd case (U3b4) where I can disable a script, but it will run the SetMessage() called function. It will not run OnGUI() or Update(), but what I call works.

    I could understand this being intended as a way to wake up scripts, but then how do I really disable a script so that it isn't listening anymore?
     
  2. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    I guess you have to put a test if (enabled == true) to all your functions before execution of their content. Not aesthetic but very simple and should do the trick.
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, scripts that are disabled don't run Update and related functions, but that's pretty much it. You can either destroy the component, or use a "if (!enabled) return;" line in the function to prevent it from executing if the script's disabled.

    --Eric