• 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 /
This question was closed Jul 04, 2017 at 12:33 PM by DotGames7 for the following reason:

Question answered, answer accepted.

avatar image
0
Question by DotGames7 · Jul 04, 2017 at 09:12 AM · unity 5uibug-perhapsenableddisabled

UI elements don't appear anymore after launching the game

Hello, I don't usually ask for help directly and always find the answer to my problem online but this time I'm clearly stuck ! I think my problem is similar to this one which is a year old and has had no answer since. The difficulty lies in the fact I don't know if it's a bug or a misunderstanding of myself.

When I first launch the project, the UI appears as it should. But after launching the game a first time, all the non-sprite elements have disappeared.

What my scripts do during play mode involves some gameObject.SetActive(true/false); and from what I understand even if I leave some objects disabled, they should still appear in Editor Mode as they are re-enabled automatically.

I tried enabling/disabling game objects with no success however when I changed one of the disappeared game objects layer from 'UI' to 'Default' and started/stopped the game, everything reappeared. I'm not able to understand why it behaves this way.

If you have any idea or if you have already encountered this problem, please let me know how I should solve it. If you need more information, just let me know I'll add it to my question ! Thanks.

EDIT : I'm clearly wondering if this could be a script related issue. Does enabling and disabling UI elements while in Play Mode change the way UI elements appear in Scene Mode ?

EDIT2 : I feel so dumb, after playing a bit with it, trying to add some Canvas.ForceUpdateCanvases (); everywhere, I found the case in which I had this problem : I have a blinking text and when I start the game while it is 'off', it just produces the above bug. However, if I start the game while the blinking text is 'on' it just works fine thus explaining the erratic nature of the issue I encountered. I'll just take a break and then will look at the blinking code (5 lines long :| ) to see what was the cause of the issue. Even if I had put some code here, I wouldn't have thought it was caused by such a meaningless part of all the code I currently have. Sorry for the inconvenience, I'll keep you up !

EDIT 3: Found the problem and put it as an answer below. Also removed the picture as they aren't relevant to the issue. Thanks for the help though.

Comment
Add comment · Show 3
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 SohailBukhari · Jul 04, 2017 at 09:45 AM 0
Share

show canvas setting

avatar image SohailBukhari · Jul 04, 2017 at 09:47 AM 0
Share

$$anonymous$$ake sure you canvas tag is not set to editor onlyalt text

editor-check.png (38.0 kB)
avatar image DotGames7 · Jul 04, 2017 at 10:27 AM 0
Share

I checked canvas tag and it is set to 'Untagged' whether my UI elements have already disappeared or not : alt text

However, this is the kind of things I wouldn't have been aware of. I'm not confident with layers and such.

bug3.png (49.4 kB)

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by DotGames7 · Jul 04, 2017 at 12:29 PM

That was it ! Here is the faulty code :

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class Blink : MonoBehaviour {
     Text text; float speed = 1f; 
     Color col;
     void Start (){ 
     text = gameObject.GetComponent<Text> (); 
     col = text.material.color;
     }
     void Update () {
         col.a =  Mathf.Round(Mathf.PingPong(Time.time * speed, 1.0f));
         text.material.color = col;
     }
 }

Here you can see I was changing the default material of the 'text' component which was the default material of all my non-sprite components to an alpha of 0. When I exited play mode, the new color was keeped by the material.

I should have added another material to the blinking text or chose another way of making it blinking like enabling and disabling it.

I feel like answering your own question is a bit strange but I'll do it in order to help anyone who has the same problem given the fact this issue can be a real pain. It was really dumb !

Comment
Add comment · 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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

UI in Scene View only Rendered Backward 0 Answers

How to make a tournament bracket ? 0 Answers

Application.CaptureScreenshot with UI 0 Answers

OnCollisionEnter still called when disabled, and destroy sets enabled to false. 1 Answer

Disabling canvas renderer optimization 4 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges