Author Topic: Code is ignoring a method  (Read 4946 times)

kwelts

  • Guest
Code is ignoring a method
« on: July 16, 2012, 10:48:53 AM »
Hey there,

So I'm calling a method and have Debug.Log("") around all the code and it seems to get to a method i want to call, doesnt run the method at all, and then prints the Debug.Log("") after leaving the method.

Here is the code for the class "ServerConnection" that calls my method:

  1. //Sets static List
  2.                 CheckInCollection.SetCheckInCollection(checkInArray);
  3.                 //Instantiates an object
  4.                 DynamicButtonController dbo = GameObject.Find("Dynamic_buttons").GetComponent<DynamicButtonController>();
  5.                 Debug.Log("--->DBO GameObject");
  6.                 //Calls the method to create buttons
  7.                 dbo.CreateButtons();
  8.                 Debug.Log("--->DBO Create");

and the method it calls

  1. //Class to control creation of Dynamic Buttons
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. public class DynamicButtonController : MonoBehaviour {
  7.        
  8.         //Variables
  9.         public GameObject uiObject;
  10.         List<CheckIn> checkInList;
  11.         float dy = -77.0f;
  12.         //List<string> testString;
  13.        
  14.         /*void Start(){
  15.                 testString = new List<string>();
  16.                 for(int x = 0; x < 5; x++){
  17.                         testString.Add("#" + x);
  18.                 }
  19.                 CreateButtons();
  20.         }*/
  21.        
  22.         public void CreateButtons(){
  23.                 //Creates a starting vector for the first button
  24.                 Vector3 startingVector = new Vector3(260.0f, 480.0f, -30.0f);
  25.                 Debug.Log("--->End Vector");
  26.                 //populates the list
  27.                 checkInList = CheckInCollection.GetCheckInCollection();
  28.                 //loop to create the buttons
  29.                 for(int i = 0; i < checkInList.Count; /*testString.Count;*/ i++){
  30.                         Debug.Log("--->i: " + i);
  31.                         //adds a new gameobject to the panel
  32.                         GameObject newButton = NGUITools.AddChild(this.gameObject, uiObject);
  33.                         Debug.Log("--->newButton" + i);
  34.                         //Assigns a button name so it can be found later
  35.                         newButton.name = checkInList[i].name; /*testString[i];*/
  36.                         //instantiates a new ui object
  37.                         UILabel newButtonLabel = newButton.GetComponentInChildren<UILabel>();
  38.                         Debug.Log("--->newButtonLabel");
  39.                         //sets the label of the uiobject to the list value in i.name
  40.                         newButtonLabel.text = checkInList[i].name; /*testString[i];*/
  41.                         //Sets the location of the button
  42.                         newButton.transform.localScale = new Vector3(2f, 2f, 1f);
  43.                         //if to check if first element
  44.                         if(i == 0){
  45.                                 newButton.transform.localPosition = startingVector;
  46.                                 Debug.Log("--->transform" + i);
  47.                         }
  48.                         //all buttons after the first
  49.                         else{
  50.                                 newButton.transform.localPosition = new Vector3(startingVector.x, (dy*i)+startingVector.y, startingVector.z);
  51.                                 Debug.Log("--->transform" + i);
  52.                                
  53.                         }
  54.                 }
  55.         }
  56. }
  57.  

In a nutshell, Xcode prints "Debug.Log("--->DBO Create");" so it's getting past the method im calling but not even "Debug.Log("--->End Vector");" in my method gets printed. Any advice would be fantastic and thanks for your time.

PhilipC

  • Guest
Re: Code is ignoring a method
« Reply #1 on: July 16, 2012, 11:11:03 AM »
Are you able to reproduce this error in the editor? I know sometimes i had a hard time finding my Debug.log("") messages in the xcode output and Unity will also print ALOT of stuff at times.

I also notice that you have your "void Start()" commented out so it something else calling CreateButtons(). Maybe you have the "--->DBO Create" being printed somewhere else as well that you forgot about?

kwelts

  • Guest
Re: Code is ignoring a method
« Reply #2 on: July 16, 2012, 11:13:17 AM »
now that last bit you said might very well be it. I will check everywhere else for that trace.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Code is ignoring a method
« Reply #3 on: July 16, 2012, 01:49:41 PM »
I'm sure it'd throw a null reference exception, but are you sure your "Find" is actually returning a valid handle?

kwelts

  • Guest
Re: Code is ignoring a method
« Reply #4 on: July 16, 2012, 02:31:03 PM »
so it turns out that the buttons get created i just cant see them.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Code is ignoring a method
« Reply #5 on: July 16, 2012, 03:15:53 PM »
But then why weren't the debug.log calls firing?

kwelts

  • Guest
Re: Code is ignoring a method
« Reply #6 on: July 16, 2012, 03:27:43 PM »
i tweaked some things (changing Find directories), and now it returns all the Debug messages, but the screen isn't changing to the buttons. It just shows that they were made but with no visual output. I cant find any duplicates of that DBO Create debug so im p-ositive its running all the way through now.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: Code is ignoring a method
« Reply #7 on: July 16, 2012, 03:41:48 PM »
While the app is running in Unity, go to the Hierarchy view and find those buttons in the tree.  Double-click them and your Scene view should zoom to them.  Could be your buttons are super tiny, or their depth might be hiding them, or several other possibilities.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Code is ignoring a method
« Reply #8 on: July 16, 2012, 03:48:17 PM »
Or the UIPanel for the buttons may have the "static" flag checked, which would prevent its geometry from being modified by the addition of these buttons to begin with.