Search Unity

Static variables sticking

Discussion in 'Scripting' started by Marble, Aug 12, 2006.

  1. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    I've defined a static variable as "false" that gets accessed by several scripts. This works fine once (I've got it so if the user clicks a button, the variable changes and some script behaviors change).

    However, after I stop the game mode and start it again for more testing, the variable, which has been set to "true" last time I ran the web player, starts out that way. I have to get Unity to recompile a script or restart it before the variable is back at its default.

    Is there something special about static variables that mean changes made to them in game mode will last later on?
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Please file a bug on that one.

    As a workaround, just set it to false from a Start function.
     
  3. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Whoa--major coincidence time! I literally just had that exact situation and was going to ask about it, though I already had figured out the Start function thing. Glad to know it wasn't just me. (Love those useful bugs though. Much nicer than the other kind. :) )

    --Eric
     
  5. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    TransformSaver is great :) (Thanks, Aarku!) Don't break it :)
     
  6. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Don't worry.... We won't.

    I've made a live cameraedit recording script for intifada (you basically set up 10 cameras, let your cutscene play and then hit 1-0 to switch between them). t records the timing of all edits, and can then be read back in editor. I didn't know about the statics (or forgot, or whatever), so I've been writing to a temp file. Can you say D'oh?

    Although possibly a bit on the hackish side of things, I'd say it can be very useful.
     
  7. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    Neat!
     
  8. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,268
    That's funny ;). Thanks.