Object/Instance variables not in expressions list

Hi, I know there have been changes to variables lately. I think this is something that got missed?
There is no mention of object or instance variables in the expression editor. It only has array stuff.

I have a sprite object called StartArea. Each instance has a variable. I tested with object variables too, it doesn’t appear in the expression editor either. They still work if typed out though.

5.4.205 -

Old version 5.3.201 -

If you have defined the variable as a string (say called Area), then you can just use “StartArea.Area”.

If it’s not declared as a string, then you’ll need to use the “ToString(StartArea.Area)

I tested the StartArea.Area, yes that’s good, it works for object variables. But I couldn’t get it to work for instance variables which I use a lot.

And even in the old versions, there was no specific mention of instance variables in the expression editor. I used to think I couldn’t refer to them, but then realised they were included in the object variables expressions.

I use a lot of instance variables. But I always added the variable to the object itself in the object variable pane with a default value, and then for certain instances of the object already in the scene editor I would click them and edit the value according to what I needed each of them to be. This is working.

1 Like

It appears like this is consistent with scene and global variables, which seems like they need to be defined before they get used.

As mentioned above, all (base) variables have to be declared since the update last month. This includes Object and Instance variables.

If you create a structure or array variable on the object, you can still dynamically create children variables of the structure/array on the instances if you want.

Thank you, this is good info, I’ll do this from now on.

I thought I *was* defining them because it was in the object properties in the scene editor. Sigh, the longer I use GDevelop, the less I seem to know.
1 Like

Edit: Ignore this post, I think I get what you mean. I don’t actually know the expected behavior.

So you’re adding them in the properties panel for an instance of the object, rather than defining them on the object?

Well if it’s any consolation, I never knew till I read your post that I could just pick an instance of the object in the editor and give it a variable and none of the other objects would have a variable of that name. In my case it wouldn’t have been very helpful though as I generally need all instances to have the same variable just with a different starting value, and it would have annoyed me to keep creating it on every object in the scene editor.

1 Like

Yes, I’ve always done it that way. I make one object, give it an instance variable and then duplicate the object. I didn’t know til today that object variables could be changed in the instance properties panel. I thought object and instance variables were completely separate and that all object variables had to be the same for all instances. Such is my lack of understanding.


Well I was thinking, maybe instance variables are supposed to be like the way you were using them, otherwise it makes no sense that you can create a variable on an instance of the object in the scene editor and it would not update all the objects to have a variable of that name. Unless it was a bug.

But I checked the instance variable page in the wiki and it seems clear that the instance variables are intended to be regular object variables. However, the page needs to be updated because it doesn’t mention how to edit the instance variables to be different values and it does not point out the purpose and usefulness of instance variables, which is being able to give certain instances a different starting value than default. It should possibly give an example too.

I’m wondering if you should make a feature request that if an instance variable is created on an instance of the object in the scene editor, the object itself is updated to have that variable with the default of whatever value you gave it for the instance you created. The rest could be as usual, as far as being able to edit the value in the object panel and in different instances in the scene editor.

1 Like