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 TokyoDan · Jun 08, 2013 at 11:56 PM · gameobjectmonobehaviourinstance

What is an instance of a GameObject?

Does dropping a GameObject into the Hierarchy (scene) or dropping a GameObject into a public variable in a script attached to a GameObject in the Hierarchy create an instance of that GameObject?

And does that also make instances of all the components (especially script class files derived from MonoBehaviour) on that GameObject?

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 TokyoDan · Jun 09, 2013 at 02:34 AM 0
Share

Thank you Steve. That's what I thought. I just wanted to be sure.

So it means that when I call a method in a script component of an instantiated GameObject the called method doesn't have to be a static method. (I know when you call a method on a Class (no instance) either the method has to be static or else you have to create an instance of that Class, e.g.

ClassName a$$anonymous$$ethod = new ClassName;
a$$anonymous$$ethod.methodName();

avatar image robertbu · Jun 09, 2013 at 02:39 AM 0
Share

If a script is attached to a game object or prefab and you do an Instantiate() on that game object, you get a new copy of the game object including all the scripts attached to that game object.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Slobdell · Jun 09, 2013 at 01:16 AM

If you drag the object into the scene, it will have an instance created upon running your app. If you place a gameobject in a script, it will be instantiated if you instantiate it...

GameOjbect newObject = new GameObject();

When you instantiate a gameobject by placing it visually, or programatically, all attached scripts will also be instantiated with it. If you have a prefab with a script attached say, they essentially become one object. Can't instantiate one without the other unless you write some code to detach and destroy the script.

Steve

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 aldonaletto · Jun 09, 2013 at 01:58 AM 0
Share

Dropping an object into a public variable only assigns the object or prefab reference to it. If it's a prefab, you must instantiate a clone in order to have a real scene object - the prefab itself is a kind of "game object template", not an actual scene object.

avatar image TokyoDan · Jun 09, 2013 at 02:43 AM 0
Share

I know this is going to be stupid, but here goes...

What if you place an instantiated GameObject(2) (from scene or hierarchy) into a script that is on an already instantiated GameObject(1). When you run the app will GameObject(2) be accessible as an instance or just as an uninstantiated Class?

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

16 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

Related Questions

Fade 2 out of 3 gameobjects on the screen who have the same material 2 Answers

How to add an existing script instance to a GameObject 2 Answers

Destroyed object not comparing to null 5 Answers

Is there any way to receive callbacks from the Unity Engine without creating a MonoBehaviour? 4 Answers

Waypoint NullReferenceException: Object reference not set to an instance of an object error please help. 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