The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hi guys.

As we know the properties of a class are variables and they have a name.For example if i want to use the property "motion" of the KinematicBody2D i have to give a type on the variable.For example: var motion=Vector2(), and i can use the propery "x" of Vector, for example motion.x=200.I noticed that if i change the name of the property "motion" in all fields, for exampe move.x=200 then the code has no problem, but, concerning the property "rotation" i can use it directly :(rotation +=2*_delta),and if i change her name then the code has problem.Also, about the property "rotation" the code has problem too if i try to give to her a variable type.
My question is:What's the point with the properties?The names of them are predetermined and we can use them directly or we have to give a type to them first?I noticed that both apply in some cases.

Thank you and i am sorry about my english.

in Engine by (223 points)

1 Answer

+1 vote
Best answer

Sorry but KinematicBody2d does not have a motion property.

Maybe this will help:
You can think of the nodes as predefined scripts (it's more complicated but that's a good way to understand them). These "scripts" already have some variables that are defined, in your example the rotation variable. Many of them can be edited in the inspector. They are called properties.

On the other hand each node can have another script made by you, that can contain variables that you created yourself. The scripts can also edit/set the value of the nodes properties.

Please note also that Vector2() isn't setting a type, but instead it returns a value (an empty Vector). You do not have to set the type of any variable, though it is possible since godot3.1. Vector2 is a datatype that contains a x and a y. Of course the code will make problems if you change the name of a property, because the "script" that defines the nodes basic behavior tries to find it. Changing the type of a property leads to trouble to, because godot is expecting a certain type.

Did that help you? I hope so. Feel free to ask more questions if not.

by (864 points)
selected by's more clear now but i have two more questions.
When i press the F4 button and i type "KinematicBody2D", in the properties i can see a word "motion".So, what is it?
And second:Why, when i changed the "motion" word in "move" word in my Script, then the code had not any problem?

I am sorry, I am still using godot3.0 most of the time so I didn't find it in the first place. This motion isn't a property of the object. If you look into the inspector you can see that it is the name of one section there, holding the property sync_to_physics.

Secondly: From what you said I believe that you create the variable motion inside your script, which means it is somehow a local variable. So changing all occurrences of the name to something else will not affect any other script, thus let everything work fine. But it would become a problem if you would change the name in one place only.

Does that sound logical. Good luck!

Now its apsolutely clear. I mean about the "holding the property synctophysics".Now makes sense and the issue with the variable name "motion"You are right!

Thank you very much!

You are welcome, glad I was able to help.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.