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
1
Question by ComeSweetDeath · Sep 07, 2014 at 06:59 PM · object

What is the concept of "object" class (not gameObject, just object) in Unity scripting?

I was reading through this : http://docs.unity3d.com/ScriptReference/Object.html and it seems that "objects" don't exactly work the same as "gameObject", in that it is never explicitly typed out like gameObject.

For example:

  • With gameObject, you can type something like: gameObject.camera

  • But with object, instead of typing Objects.FindObjectsOfType(HingeJoint), you just simply type FIndObjectsOfType(HingeJoint). Or instead of typing Object.Instantiate(...), you simply type Instantiate(...).

I also tried to explicitly type out objects in MonoDevelop and an error tells me: Unknow identifier 'objects'/'Objects'.

So I'm a bit confused... why is 'object' allowing for this kind of omission? Is it a concept that is different to gameObject?

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

3 Replies

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

Answer by AyAMrau · Sep 07, 2014 at 07:16 PM

Object is the base class of all objects unity can reference. If you look through the documentation for other elements, under the name you will see something like Namespace: Inherits from: [Class]. It may not always be Object but if you keep clicking the names you will (in not all but many cases) eventually arrive at Object.

The reason for this is simple, and what inheritance is in part for, it gives all the children a set of common variables and behaviours. Which allows the code to aggregate objects under a base type and use the common elements. In most cases you will probably not want to go as deep as Object.

GameObject inherits directly from Object and specialises it to represent objects that can be used in Unity scenes. Therefore it has access to (public and protected) members of Object.

But Object and GameObject are not equal.

Also within a MonoBehaviour you can use Instantiate or FindObjectsOfType without referring to anything, because MonoBehaviour inherits from Object (therefore you own script that inherits from MonoBehaviour also inherits from Object.

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
1

Answer by kacyesp · Sep 07, 2014 at 07:14 PM

GameObjects represent objects that are actually in the scene.

Object is the base type for all objects in Unity. An example of an Object that is not a GameObject is a script.

Here's another answer to this question: http://answers.unity3d.com/questions/707570/object-vs-gameobject.html

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
1

Answer by BMayne · Sep 07, 2014 at 07:14 PM

Hey There,

I am going to run over this very quickly :)

object (lowercase o ) is the base class for all .Net (C#) classes. It's the furtherest down you can go. Anything in .NET can be downcast to it.

Object (uppercase o) is Unity's base class. Everything you see in Unity project ie. Folders, Scenes, Scripts, sprites, music, etc are of base class Object. This becomes very important when doing editor scripting.

If you know about Polymorphism the base type Object becomes very useful for generic programming. If you don't know about it I would suggest reading up as it's a staple of OOP.

Regards,

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

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

25 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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Help with hiding an object on trigger enter 1 Answer

Trouble grabbing and holding a cube. 0 Answers

Triangle Mesh Problem 2 Answers

help with game error 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