Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 Skatola · Apr 28, 2017 at 08:23 PM · nguicomponentsaddcomponent

how to access to a component previously removed and readded

This is my problem, i'm trying to make work an NGUI component called typewritereffect for simulate the typewriter on a string. The component write the string as typewriting then i need to remove it and add it the typerwritereffect component to the string to make it work again. But i have a problem, after i remove the component and i add it again there is no way to point again to that component. I have no idea why. This is my code:

 public void interazione(){
     Destroy (main_label_obj.GetComponent<TypewriterEffect> ());
     main_label_obj.AddComponent<TypewriterEffect> ();
     NGUITools.SetActive (interaction_button, false);
     type_component.charsPerSecond = 25;
     main_label_obj.GetComponent<TypewriterEffect> ().ResetToBeginning ();
     EventDelegate.Add (main_label_obj.GetComponent<TypewriterEffect> ().onFinished, function_test);
     main_label.text = testi [counter_dialogue];
 }


so..i can easily add an eventdelegate, or change the charspersecond prop to the original component, but if i do that after the component replacement nothing happen, any idea why? thank you all

Comment
Add comment · Show 6
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 ADAMN721 · Apr 28, 2017 at 08:51 PM 0
Share

I'm having trouble fully understanding your question but.... Do you NEED to destroy the component? Would it be possible for you to just set it to inactive as you are the NGUITOOLS?

avatar image Skatola ADAMN721 · Apr 28, 2017 at 10:09 PM 0
Share

thank you for your help, yes i have to destroy it cause it works just one time, so if i replace my text string it doesn't work anymore, i have to destroy the component and make a new one but i can't work on it, have no idea why

avatar image PizzaPie · Apr 29, 2017 at 04:13 PM 0
Share

Try to apply any changes after the destroy on the next frame

 public IEnumerator interazione()
     {
         Destroy(main_label_obj.GetComponent<TypewriterEffect>());
         yield return null;
         main_label_obj.AddComponent<TypewriterEffect>();
         NGUITools.SetActive(interaction_button, false);
         type_component.charsPerSecond = 25;
         main_label_obj.GetComponent<TypewriterEffect>().ResetToBeginning();
         EventDelegate.Add(main_label_obj.GetComponent<TypewriterEffect>().onFinished, function_test);
         main_label.text = testi[counter_dialogue];
     }

Quite bad practice to destoy a component and re create it, make sure there is no reset function on the component.

avatar image Skatola PizzaPie · Apr 29, 2017 at 04:31 PM 0
Share

doesn't work... sadly i asked to the developer of NGUI and he said "you can always AddComponent() to reset it after it finishes.", so i suppose remove it and it again it's the only way, i just don't understand why unity have problem to identify the new component

avatar image PizzaPie Skatola · Apr 29, 2017 at 04:37 PM 0
Share

Probably has to do with the initialization of the Component or some kind of registering it, don't know exactly. The above method works for a Collider probably will work for your component too.

Show more comments

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

101 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

Related Questions

How can I AddComponent() now? 3 Answers

How to add Canvas Scaler and Graphic Raycaster to Canvas in code 1 Answer

Share common data for all components in gameObject 1 Answer

How to show the Architecture of my game? 0 Answers

GetComponent of a class of generic type 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