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 /
This question was closed Aug 29, 2018 at 12:34 PM by pako for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by riotsw · Jan 06, 2018 at 01:01 AM · c#buttoneventsystemeventsonclick

Button doesn't work when returning to scene (android)

Using Unity 5.6.3p2

Building a game for Android.

I have a scene called "Main" that is active when the app starts. There is a single button called "Create". Button takes you to "Scene2". In Scene2, there is a button called "Save". "Save" does some stuff in a function, and the last line of that function is: SceneManager.LoadScene("Main");

The function works... the things that are supposed to happen happens, and then the user is returned to "Main".

However, Now the "Create" button no longer works. It still highlights when you press it, but it doesn't take you to "Scene2" anymore.

???

My "Main" Scene does have an "EventSystem" and I do have "Force Module Active" in the checked state.

My question is similar to https://answers.unity.com/questions/913093/ui-buttons-stop-working-after-i-load-another-scene.html but I think the answers are not applicable to the current version of Unity.

More details I should probably add:

In my "Main" scene, I have a object I call the "Game Controller". Within this object is a script component and that contains this:

 void Awake ()
     {
         if (Instance == null) {
             DontDestroyOnLoad (gameObject);
             Instance = this;
         } else if (Instance != this) {
             Destroy (gameObject);
         }
 
     }



(I should also add that I'm fairly new to Unity)

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 pako · Jan 06, 2018 at 02:23 PM 0
Share

Hi @riotsw I've had a look at the similar question you mentioned. Have you tried the solutions proposed by fregas and Fdudka?

I suspect that this is happening because the "subscription" to the button's onClick event has been somehow lost. If none of the previous solutions work for you, I could post some code to show you how you can subscribe to the buttons events in code, ins$$anonymous$$d of setting a method to run in the Inspector. Let me know.

avatar image riotsw pako · Jan 06, 2018 at 03:46 PM 0
Share

Hi @pako There was one comment on that post: "the event system game object was not in a persistent game object in the hiearchy, so it didn't have DontDestroyOnLoad. I just made it part of another GameObject that had DontDestoryOnLoad AND followed Ironcross's advice for "Force $$anonymous$$odule Active" and all was well again"
I think this is probably related to my issue. As mentioned in my OP, I do have a DontDestroyOnLoad thing in a GameController object in my $$anonymous$$ain scene. There is also An EventSystem object in the $$anonymous$$ain scene. But I don't understand how I would attach my EventSystem object to a persistent game object....? That might be what I'm missing (again... fairly new to unity)

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by pako · Jan 06, 2018 at 05:19 PM

The DontDestroyOnLoad on your GameController is relevant (i.e. affects) only the GameController. The comment refers to the GameObject of the EventSystem, i.e. the GameObject named EventSystem, with the EventSystem component to it. Although I had second thoughts about it, what the comment meant, was to include another custom script in the EventSystem GameObject, with the DontDestroyOnLoad (gameObject) statement in Awake() (as you've done for your GameController).

However, as I've said above, I've had second thoughts about this, since your "Main" Scene already includes an active EventSystem, which responds to the click of your button, and takes you to Scene 2, which also includes an active EventSystem, as you can, again, click on the button and go to back to the "Main" Scene.

Therefore, to start with, the EventSystems in both scenes function properly, so there's no question about using a DontDestroyOnLoad statement to preserve any EventSystem.

Additionally, since the EventSystem in the "Main" Scene starts active, when this scene loads again (after Scene 2) the EventSystem should, be in an active state again.

Just to make sure, please check if the EventSystem is active in the Hierarchy of the "Main" Scene, after returning from Scene 2.

Is there a reason why you are not using one of the latest Unity versions? I am using v.2017.2.1 and I tried to replicate the problem, but couldn't.

I just created a button in an empty scene, and attached the following script to it:

 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class SceneChanger : MonoBehaviour
 {
     public int NewScene;
 
     public void ChangeScene()
     {
         SceneManager.LoadScene(NewScene);
     }
 }
 
 

I configured the button's Inspector to run`ChangeScene()` on each button click, duplicated the scene, and added both scenes to the build settings. I also set the NewScene variable to '1' in Scene 1, and '0' in Scene 2.

The scenes were changing back and forth just fine, both in Editor Play mode, as well as in the Android build I made.

So, maybe you should try and replicate the above in a new empty project. If you still have a problem, it could be related to the Unity version you are running.

Otherwise, there could be something in your code, which prevents scene 2 to load the second time, in which case, it would be good to post some of your code.

Comment
Add comment · Show 16 · 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 riotsw · Jan 06, 2018 at 05:34 PM 0
Share

@pako Thanks so much. :) First... regarding the Unity version, when I "check for updates" it returns that I have the latest...?

Then regarding whether or not EventSystem is in an "active" state. How do I know that? When I run it, and go between scenes, nothing seems to change when I look at in the hierarchy (nothing changes with any object in the hierarchy for me).

I will try replicating in an empty project next just the way you described...

oh wait... I see on the website re: 2017. Will try that first. :)

avatar image pako riotsw · Jan 06, 2018 at 05:54 PM 0
Share

You are running v.5.6.3p2, which is a "patch" version, as signified by the "p2" suffix, and it's not recommended (by Unity) to run patch versions, unless they help solve a particular problem, and even then, only until the next main release comes out. I don't know why "check for updates" reports that you are running the latest version, but "Unity 5" is in version 5.6.5 and "Unity 2017" has been out for quite a while now, the latest version is 2017.3.0: https://unity3d.com/get-unity/download/archive

$$anonymous$$ake a backup copy of your project (just in case) before upgrading, because some of your scripts may be automatically upgraded after you open the new Unity version.

I just mean that the GameObject of the EventSystem will be grayed-out in the Hierarchy, if it is in an "inactive" state. However, if nothing is changing, it seems to be active.

avatar image riotsw pako · Jan 06, 2018 at 06:18 PM 0
Share

Ok - so I'm on 2017.3.of3 now

$$anonymous$$y original project still has the same problem.

So I made an empty project as you described and made the same SceneChanger script. But I don't see where I put in the NewScene number when I attach the SceneChanger to the OnClick() of my button...?

alt text

capture.jpg (13.8 kB)
Show more comments
avatar image khaledr · Aug 29, 2018 at 11:58 AM 0
Share

in my case i still having this issue in android. i tested all the advises you mentioned ...

avatar image pako khaledr · Aug 29, 2018 at 12:33 PM 0
Share

@khaledr it's better to post a new question, since this one has already been answered. Since you've followed my advise and it's still not working for you, it must be something different, even though it looks the same. Hence the need for a new question.

Follow this Question

Answers Answers and Comments

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

Why does my code hang when calling a script in a multi-nested event function 0 Answers

How to reference the previously selected game object? 1 Answer

How to modify a button component with C# 0 Answers

Multiple Cars not working 1 Answer

issue rendering animation on button click 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