# My GML object doesn't want to inherit variables

here's the error that I can't seem to get rid of.

FATAL ERROR in action number 1 of Step Event0 for object side2_obj3:

Variable side2_obj3.sidePick2(100004, -2147483648) not set before reading it. at gml_Object_side2_obj3_StepNormalEvent_1 (line 1) - if (sidePick2 == 1)

this object is inheriting from an object that holds the variables sidePick1 and sidePick2. I stripped the level down to just the object to see if this was being caused by a code collision and the issue seems to be persisting.

EDIT

I gave tried calling the following function

Event_inherited ()


And it didn't work

• Avoid marking an answer as accepted if it doesn't work :P – Vaillancourt May 18 '17 at 16:56
• Sorry, thought it was the approved button. Still kind of new here. – Carson May 18 '17 at 17:01
• Sure, no problem :) – Vaillancourt May 18 '17 at 17:02
• Share your project – Dmi7ry May 19 '17 at 6:26

Make sure you called

event_inherited();


In the create event of child object (side2), because if you put something else in the event (create event in this case), the inheritance won't work without manual call of the function.

• I have in fact tried that. I know GML has assumed inheritance unless otherwise stated but I know how C++ can be whiny about this exact kind of issue so I looked into explicit inheritance in GML. – Carson May 18 '17 at 15:00

I figured it out. in GML, event_inherited only works on step 0 and forward, relative to the object. if the creation code for an object executes on the same step as the creation code for a child, the child will not have time to inherit. Normally this wouldn't matter, but if the creation code for the child alters the local version of a variable provided by the parent, the object might not have the time to acquire and set the inherited variable before attempting to access it.

Kirk Summation : imagine 2 cars, identical except one doesnt have an ignition. its okay because you have left instructions on which ignition to use and how to install it. but the instructions say to drop the part in at the second the race starts. obviously, the car wont go because the ignition isnt installed until the second the race starts. same basic concept.

• you should call event_inherited() in create event, before any other actions. – Dmi7ry May 20 '17 at 7:19
• I tried that. The issue is that on step zero of an object's timeline the variables are still being set, so children have nothing to inherit. For that reason you can't run creation inheritance that executes on the same step as the parent's creation because there is nothing to inherit until after that step – Carson May 20 '17 at 18:06