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 Wakeful · Jan 20, 2015 at 02:37 AM · c#editorprefabvariablegetcomponent

Changing Prefab Variables From Another Script In Editor

Hey,

I have a prefab with script X on it variable XX. I also have a script Z with the variable ZZ on another object(not the prefab). While in the editor I want to be able to change variable XX to ZZ. So what ever ZZ is XX always equals on the prefab. I also want to use script X on more than one prefab with different XX values. If im not clear about what im asking please let me know so I can clarify...Thx

~Wakeful

Comment
Add comment · Show 2
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 fddefdef · Jan 20, 2015 at 07:30 AM 0
Share

So you want to access script X which is on a prefab from a script attached to an object in the scene?

avatar image Wakeful · Jan 20, 2015 at 04:14 PM 0
Share

Yes that is correct. Script X is on a prefab and Script Z is on a gameObject in the scene.

1 Reply

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

Answer by abi-kr01 · Jan 20, 2015 at 05:12 PM

Here is something that i have done for my projects it might help you as well

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Z : MonoBehaviour {
      public int zz; //varible   zz on main script
 
     void Start () 
     {
         update_value ();
     }
     
  
     void update_value () 
     {
         //finding all gameobjects that are avail on scene 
         foreach (GameObject obj in UnityEngine.Object.FindObjectsOfType(typeof(GameObject)))
         {
             zz=Random.Range(0,100);    
             if (obj.transform.tag == "prefab")  // finding and adding new value in xx with new zz for each gameobjects with prefab tag 
             {
                 print("Before update "+obj.GetComponent<X>().xx);
                 obj.GetComponent<X>().xx=zz;
                 print("After Update"+obj.GetComponent<X>().xx);
             }
         }
     }
 }

Comment
Add comment · Show 3 · 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 abi-kr01 · Jan 20, 2015 at 05:13 PM 0
Share

here is the script that is attach to all prefab

 using UnityEngine;
 using System.Collections;
 
 public class X : $$anonymous$$onoBehaviour {
 
     public int xx;
     
      
 }

avatar image Wakeful · Jan 21, 2015 at 05:33 AM 0
Share

Close but not what im looking for, but thanks tho. I want to be able to update the prefab before I run the game. What im doing is only going to be for when im in the editor anyways, but it would make it a lot easier for me when Im creating alot of prefabs and all have then in a list.

avatar image abi-kr01 · Jan 21, 2015 at 07:13 AM 0
Share

the "Z" script is of type "mono behavior" you can use "EditorWindow" and modify script to do the same task

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Referencing in a prefab 1 Answer

Can someone tell me if its possible to add this into a custom editor to edit values? 0 Answers

Serialize problem with Unity Editor, values reset on game execution! 1 Answer

script with individual function for each gameObject or public script variable to solve inventory system problem 1 Answer

Need of having prefab in Scene 1 Answer


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