Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 emc233 · Dec 28, 2013 at 07:41 AM · prefabcomponent

Is this supposed to happen to scripts added to prefabs?

I wrote a program to add a script to a prefab. I kept running and stopping the scene to test variables of other things. After a while, my games fps dropped to 3fps and the prefab had many scripts.

I was just wondering is this intentional that the instantiation of a prefab applys changes each time a script component is added? What is a potential use of this feature?

I got rid of the scripts by adding a line to destroy the added script if there. I could have prevented this by checking if the game object already had the script attached.

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

1 Reply

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

Answer by asafsitner · Dec 28, 2013 at 09:23 AM

You basically solved your own problem.

This behavior is intentional - your program just kept adding these script components to the source prefab instead of the instantiated game object, so each new instance had all of them attached.

Comment
Add comment · Show 5 · 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 emc233 · Dec 28, 2013 at 05:29 PM 0
Share

Here is my code. How would I add it to the instantiated gameobject ins$$anonymous$$d of the source prefab?

 var s : String = "";
 var all : GameObject[] ;
 
     function Start () 
     {
         boo = true;
         all = Resources.FindObjectsOfTypeAll(GameObject) ;
         
         for( var o : GameObject in all)
         {
             s = o.name;
             if( s.Length <= 4  || String.Concat( s[0] , s[1] , s[2] , s[3] ) != "Bone")
             {
                 if(o.renderer && o.gameObject.GetComponent(fm) == null ) //     && PrefabUtility.GetPrefabType(o) != PrefabType.$$anonymous$$odelPrefab )
                 {
                 //print(PrefabUtility.GetPrefabType(o));
                 o.AddComponent(fm);
                 }
             }
         }
             
     
     }
 
avatar image asafsitner · Dec 28, 2013 at 05:48 PM 0
Share

On what game object is this script located and when exactly is it supposed to add the component?

avatar image emc233 · Dec 28, 2013 at 06:55 PM 0
Share

It is attached to a gameobject already in the scene. It adds the component when the function Start() is called.

avatar image asafsitner · Dec 28, 2013 at 07:03 PM 0
Share

Why not have this piece of code in the same place you instantiate your prefabs?

avatar image emc233 · Dec 28, 2013 at 07:14 PM 0
Share

I have lots of stuff in the scene (that are not necessarily prefabs). I just noticed this property and thought it was weird and possibly a bug. I don't use code to instantiate some prefabs as well.

The whole point of this interaction was to change the materials of all game objects in a scene. I did this successfully. I guess you answered my question. Thanks.

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

19 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

Related Questions

How to attach a prefab to a script that is added dynamically 0 Answers

Updating variable on another script. It is not working. 2 Answers

Get child component of a prefab to reference with another prefab 1 Answer

Shooting problem - bullet shoots diagonally when facing forward 2 Answers

Editor utility for handling nested prefabs.. 4 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