Author Topic: UIButton OnClick settings get erased from Editor (3.0.0d)  (Read 5825 times)

yohann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
UIButton OnClick settings get erased from Editor (3.0.0d)
« on: September 25, 2013, 08:19:12 PM »
I'm using the new feature in the editor to assign a method to a UIButton's OnClick stuff. This UIButton object is part of a prefab that spawns many buttons at runtime that load different levels. When I test the game, everything works as it should, but when I stop the game, the OnClick stuff gets reset to it's empty state.

HOWEVER...

If I'm not viewing the OnClick stuff in the Inspector while doing the test above, everything stays saved...nothing gets erased. It's only when I have the OnClick stuff showing in the Inspector does stuff get erased after I stop the game.

[UPDATE] just to clarify, you need to load a different level while testing the game to see the OnClick settings get reset in the Inspector
« Last Edit: September 25, 2013, 08:32:40 PM by yohann »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton OnClick settings get erased from Editor (3.0.0d)
« Reply #1 on: September 25, 2013, 08:42:50 PM »
Load a different level while testing the game? The way the delegate system works is it keeps a reference to a MonoBehaviour, as well as the string name of its function that it should call. This is what's stored. If the reference becomes null for any reason, the delegate is automatically removed. So whatever you are referencing apparently gets destroyed. Do you have the prefab referencing some in-scene game object?

yohann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIButton OnClick settings get erased from Editor (3.0.0d)
« Reply #2 on: September 25, 2013, 09:02:58 PM »
I'm not trying to maintain references across levels, I'm just saying that loading, say, Level 1, resets my UIButton OnClick settings for Level 0. No errors; it just resets. The reason this feels like a bug is that it only resets if I'm watching it in the Inspector. If I make sure something else is visible in the Inspector when I run the game, it works great.

You know how when you run a game, you can jack around with Inspector settings, but when you stop the game it goes back to pre-run settings? That's what it feels like it's doing...treating my OnClick settings as if I set them while running the game and then resets them when I stop the game.

[UPDATE] Here's an even simpler example: OnClick settings don't seem to be saved at all with the scene. I set it, save it, close it, open it, and it's reset. :(
« Last Edit: September 25, 2013, 09:40:28 PM by yohann »

yohann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIButton OnClick settings get erased from Editor (3.0.0d)
« Reply #3 on: September 26, 2013, 10:02:42 AM »
Can anyone else confirm that UIButton OnClick editor settings are not being saved after closing Unity? (See attached)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton OnClick settings get erased from Editor (3.0.0d)
« Reply #4 on: September 26, 2013, 01:56:52 PM »
Works just fine here... What is your version of Unity?

yohann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIButton OnClick settings get erased from Editor (3.0.0d)
« Reply #5 on: September 26, 2013, 03:04:23 PM »
You have to test on a prefab. I have Unity Pro 4.2.1f4, NGUI 3.0.0e, and I am able to consistently reproduce this bug.

1) Create a UIButton prefab
2) Apply some OnClick settings via the editor ON THE PREFAB in the PROJECT ASSETS (NOT in the hierarchy, in other words)
3) Save your scene, close the scene/open another scene, and then reopen the original scene...OnClick settings are gone.

Can anyone else confirm or refute this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIButton OnClick settings get erased from Editor (3.0.0d)
« Reply #6 on: September 26, 2013, 03:18:34 PM »
A prefab cannot reference scene objects. Only a prefab instance can. A prefab can only reference components that are on itself.

That's just how Unity works, and it makes perfect sense if you think about it.

yohann

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: UIButton OnClick settings get erased from Editor (3.0.0d)
« Reply #7 on: September 26, 2013, 03:24:50 PM »
Bah. Yeah...I guess it does make sense. I'll proceed with a work-around. I really appreciate your responses.