• 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
1
Question by paulkenobi04 · Jun 06, 2020 at 11:41 AM · inputmultiplayerinputmanagersendmessagelocal

PlayerInput - SendMessages not working after changing the scene

I instantiated two prefabs with PlayerInput attached using a PlayerInputManager. In the first scene the PlayerInput-Scripts worked fine with my own scripts (lets call them scripts a). The Behavior of PlayerInput is set to SendMessages. The Gameobject with the PlayerInputManager and both PlayerInput-Prefabs are set to DontDestroyOnLoad. When Scene 2 begins i replaced scripts a with scripts b wich also should receive the SendMessages by PlayerInput, but they dont. I also tried it without replacing but it doesnt work with script a too. Does someone know the reason why?

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 HenryCGS · Jan 13, 2021 at 03:40 PM 0
Share

Hey, I'm having a similar issue. OnControlsChanged is not being called when I change the scene. Have you found a solution or is this just a bug?

1 Reply

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

Answer by djexstas9 · Jan 13, 2021 at 06:20 PM

May be some problems if you don't let the garbage collector destroy old objects and then using smth like "Find object of type" or any other Find functions which can return you reference to old object from memory instead of new one.

  • I've suffered this behaviuor when made static C# events and didn't unsubscribe from them or set the reference to MonoBehaviour or Component or GameObject to static field and not set it to null when scene reloads. Since these times I almost never use static refs to objects.

  • Also if you not cleaning up references from your manager to objects which should be destroyed it can behave like that because you don't let GC collect these objects and they're still in memory.

Comment
Add comment · Show 2 · 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 djexstas9 · Jan 13, 2021 at 06:23 PM 0
Share
  • And offtop: Consider avoiding send messages because it is very hard to debug and very easy to forget to change method name string if you renamed a method. It's very hard to read and hard to find references to a method in your ide.

  • You can replace this with c# interfaces or with making a base class for everything you need to be called by one call (but interfaces better) or using UnityEvents to call your methods through editor reference to needed method or make a small script that will call all you need when you need but $$anonymous$$essages are very very thing you should avoid.

avatar image unity_0D01B6DF5482F8E52C3D · Jun 02, 2021 at 06:36 PM 0
Share

I have a question, @djexstas9 , how can you (on the JS side after building in WebGL) go past this error: SendMessage: object Object1 does not have receiver for function moveObject

Please check out this question: https://answers.unity.com/questions/1838034/unity-webgl-unityinstancesendmessage-error-sendmes.html

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

241 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

Related Questions

how can I assign and use different controller schemes for a single keyboard? 0 Answers

Is Unity able to utilize 10 gamepads at once? 2 Answers

Is there a way to assign multiple set control schemes to gameobjects at run time for local multiplayer keyboard controls? 0 Answers

Problem with getaxis and multiple Horizontal/Vertical fields 0 Answers

Detect which local player clicked a button 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