[Solved] Instance Variables Vs object variables


#1

Hello all,
can please someone explain me the differences from instance variable and object variables ?

If I create an object in run time I usually use object variable but if I drag an object on edit screen I can use instance variables. In events, I can’t find Instance variable; object and instance variables are the same thing ?

Thanks,
J


#2

Both are different!

In the object list you have the all objects in your current scene.
Object variables are variables added by edition of your object in this list.
(right click on an object then “Edit object variables”)

On the scene you drag and drop one object, one object on scene is called instance.
An instance is one or many duplication of your original object.
If you have one object “Player” in object list, and two “Player” on scene, so you have two instances of “Player”.

Then when you click on an instance you can edit the values of the selected instance, position, width,
variables, etc…
At the bottom you see the “Instance variables” section.

If you have setup an object variable on your object the variable and the value will be shown in this section.
This variable object can be override, if you edit the value of the variable in this section, the value go to italic, this mean you have write over the object variable, and this value is now effective only on the instance selected.

If you click on a second instance, you will see the object variable, but not the value edited on the other instance :slight_smile:


#3

OK, that’s clear enough for me.

Generally I generate runtime objects (at the beginning of the scene) so using the object variable I assign a value exactly to the newly created object and not to everyone.

But I don’t understand one thing. How can I read the instance variable value ? Using the same command used to read of the object variable ?
Thank you


#4

How can I read the instance variable value ? Using the same command used to read of the object variable ?

Yes


#5

To sum it up:
object variables apply variables to all instances of an object, while
instance variables apply variables only to the instance you’ve selected.