• 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 · inputmultiplayersendmessageinputmanagerlocal

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 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 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 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 djexstas9 · Jan 13 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 Messages are very very thing you should avoid.

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

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

240 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

Related Questions

How to create and set different Player ID's to individual controllers? 0 Answers

Help needed! My Prefab won't spawn if it has input actions :( 0 Answers

Change pointer position using controller or mouse 0 Answers

3D Input Issues regarding Two Player Game - When both Left Joysticks get moved, the movement glitches 0 Answers

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

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