Author Topic: UICamera event call not seeing local field  (Read 2932 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
UICamera event call not seeing local field
« on: August 01, 2014, 05:34:14 PM »
I implemented UICamera based touch movement using a large object on its own layer to capture touches. Reading best practice to use fall through, I'm changing this but hitting a weird snag where the local field shows as populated in the Editor but is null in code.

  1. public class IO_touchTracker : MonoBehaviour {
  2.         // Uses NGUI event system to track touches
  3.         // Send details to objects
  4.         public GameObject plyer;                        // Player object to control
  5.         public behaviour_tapControl tapScript;                  // Player script to control
  6.        
  7.         void Start(){
  8.                 UICamera.fallThrough = this.gameObject;
  9.                 print ("Name "+gameObject.name);
  10.         }
  11.        
  12.         void OnPress (bool isPressed){
  13.                 Debug.Log("I was pressed on!");
  14.                 if (isPressed){
  15.                         Debug.Log("player name"+plyer.name);
  16.                         if (plyer != null){
  17.                                 tapScript.IO_Pressed (UICamera.lastTouchPosition);
  18.                         }
  19.                         // Send move command
  20.                 }else{
  21.                         Debug.Log("I was unpressed");
  22.                 }
  23.         }
  24. }
I see 'Player1' in the field 'plyer' on the Inspector, but in the OnPress event plyer == null.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamera event call not seeing local field
« Reply #1 on: August 01, 2014, 09:26:46 PM »
This isn't NGUI-related. Some reference being set or not is either Unity, or -- most likely -- just what you're doing. If it's there in inspector but not there when you play, the most likely candidate is you trying to reference a value outside of the prefab the script is on, which isn't going to work. Look closer at what you're doing.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: UICamera event call not seeing local field
« Reply #2 on: August 02, 2014, 03:57:25 AM »
It's there in the Inspector while playing though. Oh, it's working now. Looks like a bug fixed by restarting the PC over night.