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 /
avatar image
0
Question by Diogochr · Oct 08, 2016 at 07:32 AM · guieventsysteminstatiate

Event System not working with dynamically instantiated objects

Hello all, the problem is the following: (mobile game) I have buttons on the screen that call linked functions in the player object movement script as usual, but they only work if the player object is already in the scene, when i try to instantiate it dynamically (in cases when the player dies it is destroyed and then instantiated again as a clone of the player prefab), the buttons does not works as expected. No error is displayed, they simply does not respond. I know i could find workarounds, even using the legacy GUI, but i really would like to know if there are a straight solution or maybe this problem is solved in the newest unity version, i am using Unity 5.1.2f1. Thanks in advance for any reply.

Comment
Add comment · Show 8
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 $$anonymous$$ · Jul 27, 2018 at 11:22 AM 0
Share

Is this still a thing? I seem to have the same issue

avatar image pako $$anonymous$$ · Jul 27, 2018 at 11:36 AM 0
Share

I think that this behavior is quite normal. The buttons have a reference to a specific instance of the Player GameObject, together with its components e.g. the movement script that contains the linked functions. When that player instance is destroyed, the button references become null.

So, after you instantiate the new player instance, you need to programmatically assign the new instance of the player movement script containing the functions, to the buttons.

avatar image madks13 pako · Jul 27, 2018 at 02:58 PM 1
Share

Or, better yet, have a class that will manage only the GUI and it will interact with the other classes.

Show more comments
avatar image JVene $$anonymous$$ · Jul 27, 2018 at 10:52 PM 0
Share

@RealWorld, please consider a new question ins$$anonymous$$d of waking up a 2 year old question.

I was considering an answer, but then realized I'd be applying an answer to a question from 2016 when that user hasn't been on the forum since 2016.

avatar image Rick_Swash · Jul 28, 2018 at 12:25 AM 0
Share

Does the script reference the instantiated player?

avatar image MacDx Rick_Swash · Jul 28, 2018 at 12:27 AM 0
Share

I'm converting this to a comment since it is not an answer. Also, please abstain from answering old posts where the OP hasn't even been active for years.

0 Replies

· Add your reply
  • Sort: 

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multi Camera HUD buttons not working. 1 Answer

GraphicRaycaster UI event issue with Unity v5.2.0bx 1 Answer

Send UI Button Event with key press NOT onClick()??? 2 Answers

How do you highlight/select a button upon mouse enter and keep it moused over upon mouse exit? -2 Answers

Changing the Standalone Input Manager variables 2 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