Ever video, document, tutorial I come across, I keep hearing of the term ‘Instance’. Google’d it and Unity dosnt support this term.
What is this ‘Instance’?
Ever video, document, tutorial I come across, I keep hearing of the term ‘Instance’. Google’d it and Unity dosnt support this term.
What is this ‘Instance’?
“Instance” is a general language concept, not strictly limited to programming, and refers to one specific occurrence of a thing, idea, or situation.
In programming, an instance is usually created as a copy of some template, which can that have it’s properties modified to make it distinct and unique from other instances.
Unity very much supports instances, eg. via Instantiate(…)
(instantiate is the transitive verb for creating an instance)
Soooo going right down to the core here, its basically an Entity (gameobject, script, class etc)
A yes or No is my preferred answer (Takes me awhile to get my head around things)
yes and no… you’re answer isn’t wrong, but it isn’t exactly right either. Sorry I can’t give you your preferred answer. I COULD leave it at “NO”, but then you wouldn’t know.
It’s not a script, it’s an instance of a script. It’s not a class, it’s an instance of a class. Each gameobject in your scene is an instance of a GameObject.
It’s like you are an instance of human. You are A human… you are not THE human.
That gameobject isn’t THE gameobject, it is 1 of many gameobjects.
The code you write is the THE, definite article. Where as you instantiate, make instances of, duplicate, whatever english word you want to say, things that are of the type of that code organized together as a script/class.
Hey DarkEcho,
To visualize an instance think about people. All people have properties - age, name, height etc. A list of properties a person has is our People template (a template is a class in programming)
A instance is one unique version of this template that has been created with values for the properties ( a person with a name, age etc)
My person template Person - Name, Age,
An “instance” of a Person - John, 21
Another “instance” of Person - Mark, 45
If you are new to scripting you might want to check out :
http://www.wikihow.com/Understand-Object-Oriented-Programming
And about entities - Kind of. A game object is an instance of a GameObject template which contains instances of many other templates (rigid bodies, scripts, mesh renderes etc)
Ah i see now!
So in short, an Instance is just one of many of an entity. (1 of many gameobjects, scripts etc)
Cheers!
Btw, sorry if I appeared rude/demanding in the following text, some tend to drone on into the advanced stuff rather than making sure you understand the basic stuff. I hope i havnt caused offence.
Anyway thank you!
You never played a game with dungeon (raid) instances?
GW2 Instances comes to mind, no worrys i get it now
I don’t quite know how to describe it. But I can do it with code
//Create a new instance of color called c
Color c = new Color(1,1,1,1);
//Create a new instance of a GameObject called go
GameObject go = new GameObject();
it is not A instance …it is An instance …but very good answer thanks
Seriously?
If you feel the need to correct the occurence of one instance (see what I did here?) of “an instance” (Korno did spell it correctly multiple times in their post) in a 5 years old thread you need help. Urgently.
How many people would enjoy helpling others, only to be rebuked for their spelling? This forum is Content Over Form. By an infinite margin.
May I recommend you head over to SelfimportantSpellingNazis.com for a good time?
Sheesh.
No capital letter at start of sentence, missing commas, incorrect usage of ellipsis and no full stop.
An ellipsis is 3 dots, not four or five.
Pot, kettle, black?
I’ve no doubt there’s grammatical errors in my comment also, but I didn’t start this
But since it is re-opened and the older answers weren’t quite right:
“Instance” is a way to distinguish a script you write, which is like an idea, from when you put it on gameObjects, where it’s like a real thing. Those aren’t quite copies of the script – they’re real things using the script, so we call them an instance of it.
Say you write a script “public ball : MonoBehaviour { public int points; … }”. There are no instances of it yet, so you can’t change the point value. If you put that script on two balls, you now have two instances. You still can’t set the point value of balls. But you can select one instance and set points for that one, like ball1.points=5;. Thinking about them as instances is also a way to see that each script on a gameObject has its own copy of the variables.
The easiest way for me to think of it is with a car analogy. “Toyota Corolla” is a class. “The Toyota Corolla that is in your garage” is the instance.
I’ve found that for code, real-world examples are good to get the general idea, and fine for explaining to non-coders. But they break down so quickly that you have to be very careful using them to explain to programmers.
People are going to probe with follow-up Q’s. They may know more about the car market than you, but assume you picked it because of those details, or may understand it in a funny way. Even if you agree completely on how cars work, the Q’s won’t be helpful. Are the Corolla CT1 and CX packages classes or instances? What about a 1994 Corrolla – new class, or instance detail? What if we get non-dealer replacement parts? Are the Corrolla and Tercell instances of the common “CB4” design (several models are often made from a “secret” basic design). What happens when they stop making that type of car? Do lemons count as an instance? Different factories? The English left-side driver version?
You have to quickly back up and say, sure, most analogies have many points in common, but everyone knows computer analogies are only ever good for a single rough idea.
Clearly the CT1 and CX packages are classes derived from the Corolla class. Model years are probably best represented as tags in the commit history of the project. Non-dealer replacement parts are extension methods. Lemons are improperly initialized instances.