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 /
avatar image
0
Question by jt7785 · Jun 27, 2018 at 05:31 AM · instantiatebuttoninteractable

Instantiating a button prefab with interactable = false shows the button as active for a brief moment

So I'm instantiating a list of buttons via script for my level select in the main menu.

Based on your saved data and last level you've reached, I disable the buttons that follow (interactable = false).

My (small) problem is that when the buttons are shown, they are shown as active for a brief moment and then become disabled. My code is something like this:

 void Start() {
     // do some stuff
     for( int i =0; i < buttonsCount; i++ ) {
         //do some stuff
         Button btn = Instantiate( prefab, parent );
         if( condition ) 
             btn.interactable = false;
         //do some more stuff
     }
 }

Some more details:

I've also tried the "opposite" way (which is better for my case) and saved the prefab as interactable = false, and enabling it by script, but this results in the buttons showing as disabled for a brief moment and then become active.

I've also tried loading the scene asynchronously but that didn't help.

The ScrollView that holds hold the buttons is not active when loading the scene, and is getting active via script when needed to show.

I'm assuming it's related to the fact that it is inactive, but haven't gotten to test it yet (as of now). Not even sure how to fix it if that is indeed the problem.

Any thoughts?

Comment
Add comment · Show 1
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 jt7785 · Aug 05, 2018 at 02:31 PM 0
Share

Nobody? Bumping.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheKnightsofUnity · Aug 10, 2018 at 11:37 AM

Hi @jt7785,

Try running your code in Awake instead of Start. According to the documentation, Awake is called when the script object is initialised and Start may be called in other frame after Awake.

https://docs.unity3d.com/ScriptReference/MonoBehaviour.Start.html

All the best,

The Knights of Unity

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 jt7785 · Aug 13, 2018 at 01:50 PM 0
Share

This was a good idea, thanks. However, it didn't work. The thing is, all the instantiation happens before the buttons are even shown. They are the children of another element, which is inactive at first, then gets active when the player clicks "Level Select". And only then, you can see the problem. So it's not like the script hasn't run by now. (I've mentioned this on the first post)

The issue is not that important to be honest, but I'd love to hear if you have another idea.

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

119 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mouse Methods (OnMouseDown, OnMouseOver etc) stop working after certain circumstances 0 Answers

Multiple Prefab Instantiation, Camera, Button and Scroll View Question 1 Answer

How do I make a button not interactable for a set amount of time after pressed? 0 Answers

An Instantiated UI Button doesn't work; clicking does nothing. 1 Answer

Buttons not showing up the first time the menu loads, but showing up on all menu openings after 2 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