Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Alengthyname · Jun 12, 2016 at 06:02 PM · prefabsbuttonsinstantiate prefabbutton trigger eventspanel

Buttons won't get interaction in instantiated prefab

Hello,

I'm working on having jobs assigned to characters through a roster. I've made an array of units, and for each of them within the bounds that fits in my roster I'm instantiating a panel. On each panel there is a button that I've attached a simple script:

 public class Jobs : MonoBehaviour {
 public Roster charRost;
 public void JobAssign()
 {
     Debug.Log( " assigned to Job:" + charRost.selectedID);
 }
  }

where under my Roster class there's a character assignment function that works by clicking on the panel in the roster and returning the ID of the character for that panel.

I have several different panels serving as the menus, and have been able to have interaction with generic buttons and with non instantiated versions of the prefab. For a reason that I don't understand, I'm unable to get any sort of interaction with the button on the prefab ( no highlights, clicks or selects).

I've tried to get the button behavior both with OnClick() and with an Event Trigger from selection, with a prefab object with the above script in the object spot. There's an Event System in my scene and I don't think that there's a panel in the way; as I've tried not instantiating my array of prefabs and manually setting one of these where the prefabs would be instantiated and been able to interact with the button, which makes me think that it may be something to do with how I'm instantiating the prefabs.

     public void PopulateRosterPanel(int start, int last)
     {
     panelPos = new Vector3(392, 530, 0);

     pf = (GameObject)Resources.Load("CharacterRosterPanelPrefab");
     pfs = (GameObject)Resources.Load("StudentPanelStudentPrefab");

     for (int i = start; i < start + last; i++)
     {
         if (uimanager.menuID == 2 || uimanager.menuID == 3) //only populate on student or roster screen
         {

          // setting text components on the panels to the values in the character array

             panelPos += Vector3.down * (62f); //panel offset

             temp = (GameObject)Instantiate(pf, panelPos, Quaternion.identity); //temp object for panels 

             ThereCanBeOnlyOne(); //makes sure there's only 1 student
             StudentText(); //sets student text to their values 
             if (characterRoster[i].isStudent && studentDraw) //if student put it in the student, if not put it in the roster
             {
                 temp = (GameObject)Instantiate(pfs, new Vector3(0,-40,0), Quaternion.identity);
                 Debug.Log("student" + characterRoster[i]);
                 temp.transform.SetParent(studentPanel.transform, false);
                 student.StudentAssign(characterRoster[selectedID]);                   
             }

             if (!characterRoster[i].isStudent)                  
             temp.transform.SetParent(rosterPanel.transform, false); //parenting non student panels under roster               
         }
         else
             break;
     }
     studentDraw = false;
 }


There also may be something with how I'm calling this function when changing to the panel in my menu class (which I've trimmed to just the roster stuff):

 public class UIManager : MonoBehaviour {

 public int menuID = 0;

 public GameObject[] menuPanels;
 public GameObject rosterPanel;

 public Roster roster;
 public NewTurn nextTurn;

 void Start()
 {
     menuPanels = GameObject.FindGameObjectsWithTag("MenuPanel");       
     MenuSwitch(menuID);
  }

 public void MenuSwitch(int menuID)
 {
     foreach (GameObject panel in menuPanels)
     {
         panel.gameObject.SetActive(false);
     
     }
     switch (menuID)
     {
         case 2:
             rosterPanel.gameObject.SetActive(true);
             break;
     }
 }
 
 public void OpenRoster()
 {
      menuID = 2;
     roster.WipeRoster();
     roster.studentDraw = false;
     MenuSwitch(2);
     roster.PopulateRosterPanel( 0, roster.lastCharacterOnRosterScreen);        
 }

 }

If anyone could offer any insight, I'd greatly appreciate it.

[EDIT] I realized that I could do a work around with an OnPointerDown event for the button object so I'll probably do that for now. I'm still confused as to why the buttons aren't working normally, and if anyone knows I'd still appreciate the help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

57 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I cant assign a function to a button. *free candy for whoever helps me out* 2 Answers

Destroy a prefab from another class 2 Answers

Destroying Instantiated Prefab in Another Script -- Can't destroy to prevent memory loss? 0 Answers

Unity 5.3.4f1 Inconsistent Animation times between mobile devices. 0 Answers

Prefabs and public variables 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges