Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 theembracedone · Feb 06 at 01:44 PM · scripting problemerroreventsevent triggering

Subscribing to an event on a gameobject that was moved to the scene wont go through

I've got a problem where I cannot subscribe to an input event that gets fired from a gameObject that has been moved to the current scene from a previous scene, unless the gameObject I'm trying to subscribe from was moved with the aforementioned object.

.

to give a more specific example:

  1. at the start of the game, "load scene" is the starting scene, and it has gameObject with RewiredInputReader(RIR) on it.

  2. I load the scene called "Splash". gameObject with RIR gets moved to "Splash", "Splash" scene gets set active

  3. Then I load "Menu". gameObject with RIR gets moved to load scene first, "Splash" gets unloaded. "Menu" gets loaded, I move gameObject to "Menu" and set "Menu" active

  4. And then I try to subscribe to an event fired from RIR from a script that was already present in "Menu" - lets call this object "ObjectiveHandler".

.

The problem is when I try to do RewiredInputReader.Input_Submit += ClickReceived; from the ObjectiveHandler that was already present in the "Menu" scene, its script executes everything, but the "subscription" doesnt happen. I can also see RIR firing exceptions for the event firing (ie it detects the submit being received) but the subscribed script on ObjectiveHandler wont receive it.

.

Doing some testing, I found that the sub wont go through even if I sub to RIR in ObjectiveHandler's Update or manually trigger it, not even if I make RIR DontDestroyOnLoad BUT if i place the ObjectiveHandler into the load scene and they get moved together, the sub works consistently.

.

any ideas how I can bridge this problem please? (other than having everything that ever needs to sub to RIR in the load scene) Advice appreciated

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by theembracedone · Feb 06 at 03:48 PM

i think i found the culprit. There's another component that is subscribed to "submit" - if I remove the subscription from it, Tester works... but I dont see why that'd prevent the Tester from subbing especially since the other object was doing nothing with the subscription...

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

Answer by theembracedone · Feb 06 at 02:08 PM

My testing setup is this:

  1. RIR is either moved from scene to scene or is DontDestroyOnLoad

  2. an object called "Tester" with a test script is placed in the load scene to be moved from scene to scene

  3. the same "Tester" object with the test script is placed in the "Menu" scene where I am testing.

  4. The Tester contains this script (where number is just used to differentiate between the two Tester objects): public class Tester : MonoBehaviour { public int number;

           void Awake() {
                 Debug.Log("TEST Awake " + number);
                 RewiredInputReader.Input_Submit += ClickReceived2;
             }
     
             public void OnEnable() {
                 Debug.Log("TEST OnEnable " + number);
                 RewiredInputReader.Input_Submit += ClickReceived2;
             }
     
             public void OnDisable() {
                 Debug.Log("TEST OnDisable " + number);
                 RewiredInputReader.Input_Submit -= ClickReceived2;
             }
     
             public void ClickReceived2() {
                 Debug.Log("TEST Click Received" + number);
             }
         }
     }
     
    

Upon playing the game in editor, I get the following results:

the Tester that gets moved to "Menu" prints out Click Received fine, but the other one doesnt, it never subscribes, but it prints out the Awake message and also the OnEnable/OnDisable messages just fine, but it will never print out Click Received.

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

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

308 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

Related Questions

warning CS0414: The private field `GameManagerSingleton.text' is assigned but its value is never used 0 Answers

Camera Switch error 0 Answers

Same code in 2 different scripts with different outcomes 0 Answers

Rigidbody changes reference in play time to the game object that the script is attached to 1 Answer

Why do I keep getting this error? 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