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 YoungDeveloper · Nov 01, 2013 at 06:14 PM · classdatainstancetypedifference

Creating a data type instance difference question

Hey, is there a difference between creating these two kinds of data types.

 Class someClass{
 
 }
 
 someClass object1;
 someClass object1 = new someClass();

Is there a difference ?

-Thanks, Karl

Comment
Add comment · Show 5
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 Huacanacha · Nov 01, 2013 at 06:23 PM 0
Share

They are both variables to hold someClass type of objects. There is no difference between the two object1 variables themselves. In the first case no object is assigned to the value of object1 will be null. In the second case you instantiate a new someClass object and store the reference to it in the object1 variable.

avatar image YoungDeveloper · Nov 01, 2013 at 06:30 PM 0
Share

Thanks for the answer, what you mean by "null", i would still be able to access variables from if using the first case. For example:

 Class someClass{
    int a = 5;
 }
 
 someClass obj;
 obj.a = 10;

I know there will be created a new copy of that class, but that object wont be null, because i can still access a from it ?

avatar image Dracorat · Nov 01, 2013 at 06:32 PM 0
Share

If you tried what you just typed, you'd get a null reference error.

obj doesn't exist as something concrete yet. That requires use of the "new" keyword or the use of statics (which are a different beast all together).

avatar image Huacanacha · Nov 01, 2013 at 06:33 PM 1
Share

null is a special value that effectively means that 'no object is assigned'. Trying to access fields of a null variable will raise an error as it doesn't point to any real object in memory.

avatar image YoungDeveloper · Nov 01, 2013 at 06:36 PM 0
Share

Thanks, i understand now, this is the reason why you shouldn't switch to C++ time to time heh.

@Dracorat Convert your comment to answer

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dracorat · Nov 01, 2013 at 06:20 PM

Neither are data.

There is a difference, but consider this:

A Foreman gets a blue print for a new office building. He looks at the blue print.

Is the blue print an office building? No - it describes one.

He builds an office building from it. Is that an office building? Yes. Is is a blue print? No. Was it generated from a blue print? Yes.

He builds another office building. Is that an office building? Yes. Is it the same office building? No. If you smash out a window in it, will a window in the other be smashed out? No.

The class is a "blue print" from which you create new objects. The objects are the constructed instance of the class. It is something that exists in game terms. The class contains only instructions for how it should exist.

That's the difference.

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 YoungDeveloper · Nov 01, 2013 at 06:24 PM 0
Share

Thanks, but, lmao, i didn't understand any of it. Good that you didn't take hookers as an example haha.

avatar image Dracorat · Nov 01, 2013 at 06:28 PM 0
Share

You don't know what blue prints are?

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

17 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

Related Questions

How to convert System.Type into an instance or access the class variables 3 Answers

Get Superclass of Subclass in Unityscript 2 Answers

Is every Script I drag on a Gameobject an instance? 1 Answer

How to call a new instance of a class in C# 1 Answer

help with creating a static Instance in javascript 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