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 /
This question was closed May 22, 2012 at 11:35 PM by Default117 for the following reason:

Other

avatar image
0
Question by Default117 · May 22, 2012 at 11:40 AM · editorprefabreferencepublic variable

Set prefab to public variable of another script

Hi there

I'm trying to set a prefab from the project folder to a secondary scripts' public variable. This is within an editor script.

Scenario is that the first script is creating a gameobject based on certain parameters. Once the user is happy with everything, they can press 'save', which creates the gameobject into a prefab. I now want this prefab to be stored as a public variable onto another script (which is already attached to a gameobject in the hierarchy).

I can find the second script through calling something like:

         MyScript scriptInstance = FindObjectOfType( typeof(MyScript ) ) as MyScript ;

From within the first script, i'd like to then call something like

  scriptInstance.m_prefabReference = m_myPrefabIjustMade;



Any ideas? Cheers!

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 Bunny83 · May 22, 2012 at 07:20 PM 0
Share

I don't get your question...
When you have your prefab reference "m_myPrefabIjust$$anonymous$$ade" and a reference to the script instance that contains the variable, isn't the line you've posted exactly what you want?

 scriptInstance.m_prefabReference = m_myPrefabIjust$$anonymous$$ade;

I don't get the problem...

1 Reply

  • Sort: 
avatar image
0

Answer by hathol · May 22, 2012 at 11:59 AM

First thing that comes to mind is to pass the prefab path as a string to your second script and then use http://unity3d.com/support/documentation/ScriptReference/Resources.Load.html to get the actual prefab in there. Though there might be more efficient ways to do it.

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 Default117 · May 22, 2012 at 12:02 PM 0
Share

I already have the path to the prefab since the first script is generating and saving the path using the AssetDatabase. I cannot use Resources.Load since i just need to get a reference to the prefab. (I'm needing to do this for an object pool).

All i basically would like to do is reenact the process of dragging a prefab from the project folder straight onto a script that has a public variable or array of variables ready to accept prefabs. Thanks for the suggestion though.

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

Public variables set with custom editor buttons reset to prefab values on play? 2 Answers

Why does my prefab create a child by itself in ProjectView 0 Answers

How to keep reference linked when replace prefab through editor scripts? 1 Answer

Reference to Scene Object Component in Prefab Editor, 'Type Mismatch'? 1 Answer

Can't drag assets into scene or hierarchy 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