• 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 /
avatar image
0
Question by tharinduwika · Jan 10, 2021 at 12:43 AM · prefab-instance

Button component inside the prefab cannot set to interactable=false

I have a prefab with a button component and other three images like below. alt text


Now I instantiating those buttons using a script. But the interactable function doesn't work.


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class PopulateGrid : MonoBehaviour
 {
     public GameObject levelObject;
     
     public Text level_index;
     public Image star1, star2, star3;
 
     public int noToCreate;
     // Start is called before the first frame update
     void Start()
     {
         Populate();
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     void Populate()
     {
         
         for (int i=1; i< noToCreate; i++)
         {
             GameObject newObject = (GameObject)Instantiate(levelObject, transform);
 
                                
             newObject.GetComponentInChildren<Text>().text = i.ToString();
             GameObject.FindGameObjectWithTag("image1").SetActive(false);
             GameObject.FindGameObjectWithTag("image2").SetActive(false);
             if (i == 5) 
             {
                 Debug.Log("Im here");
                 Debug.Log(newObject.GetComponentInChildren<Button>().interactable);
                 newObject.GetComponentInChildren<Button>().interactable = false;
             }
             
         }
     }
 }



Console Output

alt text


What is the wrong I do here?

screenshot-2021-01-10-060544.png (10.8 kB)
screenshot-2021-01-10-061146.png (8.4 kB)
Comment
Add comment · Show 2
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
avatar image Hellium · Jan 10, 2021 at 01:59 AM 0
Share

You realise you print the value of interactable BEFORE setting it to false, right?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
-1

Answer by unity_5UuMRw312fOSgQ · Jan 10, 2021 at 02:39 AM

If by "doesn't work" you mean "doesn't show up in console output" you need to turn this: Debug.Log(newObject.GetComponentInChildren().interactable); newObject.GetComponentInChildren().interactable = false; into this: newObject.GetComponentInChildren().interactable = false; Debug.Log(newObject.GetComponentInChildren().interactable); Because right now you send that value to the console BEFORE switching them off. Feel free to tell me if this fixed your issue.

Comment
Add comment · Show 1 · Share
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
avatar image tharinduwika · Jan 10, 2021 at 12:23 PM 0
Share

alt text

It's not about displaying on the console. The fifth element is not disabled. That's the case.

screenshot-2021-01-10-175132.png (19.3 kB)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

113 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 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

How do I access variables from a game object from an instantiated prefab 1 Answer

Dynamic Scene Creation through Scripts? 1 Answer

How to obtain this prefab name in this circunstances 1 Answer

Bool wont change on prefab clones 1 Answer

Can't modify BoxCollider center/size on base prefab 0 Answers


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