GMS 2.3+ [SOLVED] Are instance method variables duplicated for each instance or not?

Hello! It isn't entirely clear to me how the instance method variables work. For example I have the following code:
GML:
// Object Create Event

method_var = function() {
    // do smth...
}
Will "method_var" variable contain the copy of the function, which will recreated for each new instance (and take up space in memory), or will it refer to the function that already exists in memory (like a C++ method)?
I hope I have phrased my question clearly 😅
I tried to find an answer on the forum, but I couldn't find anything suitable...
 
Hello! It isn't entirely clear to me how the instance method variables work. For example I have the following code:
GML:
// Object Create Event

method_var = function() {
    // do smth...
}
Will "method_var" variable contain the copy of the function, which will recreated for each new instance (and take up space in memory), or will it refer to the function that already exists in memory (like a C++ method)?
I hope I have phrased my question clearly 😅
I tried to find an answer on the forum, but I couldn't find anything suitable...
It appears to refer to the already-created function. You can test it yourself with show_debug_message(my_method). Keep in mind that this seems to apply only to objects.
 

Tyg

Member
Instances use their objects method unless you override the method
if your parenting your object events can be overridden by a sibling then then instance will use its own event
 
Top