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 ExoArc · Aug 31, 2014 at 08:48 PM · editormonobehaviourspell

Assign a MonoBehaviour script to a variable.

Hi, I need help with this little issue I'm having.

I'm trying to create a custom editor to create spells faster. And I want to be able to assign a script to a variable so I can have default behaviour and custom behaviour.

This is what my editor looks like currently http://prntscr.com/4ibw62

So what I'm trying to do is assign the script to a variable so I can get it's Type and AddComponent it to the created GameObject.

I'm just having trouble with actually assigning the script.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by kacyesp · Aug 31, 2014 at 08:51 PM

 void Awake() {
     AbilityCreator abilityCreator = GetComponent<AbilityCreator>();
 }
Comment
Add comment · 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
0

Answer by rutter · Aug 31, 2014 at 08:53 PM

assign the script to a variable

It's important to distinguish between classes and objects. If you don't understand the difference, there are thousands of tutorials around the net to explain it. In a nutshell, a class is analogous to a blueprint, and an object is a house built from that blueprint.

So, let's say you have a variable like this:

 var myScript : MonoBehaviour;

In that case, myScript is a reference to a MonoBehaviour object. Possibly one that exists in your scene, or maybe one that's attached to a prefab.

On the other hand, if you're trying to get Unity to serialize a reference to a class, I'm sorry to say that's not supported by Unity's built-in serialization engine. You can put together some workarounds. The simplest is to serialize a string, enum, or some other basic type so that you can use a script to map that back to your desired class.

Unity's serialization is somewhat limited, but you can work within those limitations to accomplish many things.

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 ExoArc · Sep 05, 2014 at 09:06 PM 0
Share

That is not exactly what I meant, I meant assigning the script to a variable as in how unity does it with selecting a $$anonymous$$onoBehaviour when a script is attached to a GameObject, textfield like thing with the circle to the right.

But I sort of found what I was looking for, it's called $$anonymous$$onoScript. Sort of as in you can't really do a whole lot with it.

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

Call Editor function from Monobehaviour script 1 Answer

MonoBehaviour execution order from Edit to Play mode and back. 2 Answers

Large serializable field in a MonoBehaviour causing poor performance in Inspector 1 Answer

How do I detect that MonoBehaviour is modified in the Editor? 2 Answers

Extending editor without script on GameObject? 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