Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Cirrocumulus · Feb 10, 2018 at 08:51 AM · inspectorscripting beginnercomponents

Public script references in the Inspector

What does it mean exactly when a public Inspector variable is of a custom class, like this:

 public MyClassName myClass;

I know that a class inheriting from MonoBehaviour is instantiated when dragged as a component onto a GameObject. I believe most MonoBehaviour scripts are meant to be used in this fashion. But what happens when I drag the script onto an Inspector field? Is it instantiated (probably not)? Some notable use cases would be very much welcome. Thanks.

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
1
Best Answer

Answer by pako · Feb 10, 2018 at 01:20 PM

But what happens when I drag the script onto an Inspector field?

You can't (try and see). Unity won't let you drag a script from you Assets folder in an Inspector field, because if I understand your question well, this is what you had in mind. And this of course, is because an instance of this script hasn't been created yet.

And when you drag a GameObject with a particular script on it, on to an Inspector field, the field contents display "GameObjectName. (MonoBehaviourName)", indicating the instance.

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 Cirrocumulus · Feb 10, 2018 at 01:22 PM 1
Share

Thank you!

avatar image
0

Answer by hexagonius · Feb 10, 2018 at 10:16 AM

it's basically the same as if you did int i = 5. it's a way of doing the assignment via inspector. What Unity does is literally writing a list of everything existing in a scene. when the scene content is created the underlying system brings those things together that have been linked like that in the inspector so you don't have to do that in code. its not instantiating anything, just referencing.

Comment
Add comment · Show 2 · 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 Cirrocumulus · Feb 10, 2018 at 12:34 PM 0
Share

But it is referencing a class, not an instance, right? How would this be used (except for allow a prefab that contains that script to be dropped onto the field)?

avatar image hexagonius Cirrocumulus · Feb 10, 2018 at 06:19 PM 1
Share

As pako said, it references an instance in form of a prefab or a scene gameobject (any gameobject with the script attached).
they only ever exist on gameobjects and get created by the engine in C++ form. so, it's referencing an instance of the class. that's why you can't reference the script only.

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

80 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

Related Questions

Cannot enabled / disable a script component? 2 Answers

Unity can't see any scripts 0 Answers

(Bolt) Can you collapse Variables in Inspector? 0 Answers

Displaying tooltips hint for variables in inspector 2 Answers

Indent or resize entire components in custom inspector 2 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