Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child resource class initialized before parent resource class #67334

Open
compmstr opened this issue Oct 13, 2022 · 5 comments
Open

Child resource class initialized before parent resource class #67334

compmstr opened this issue Oct 13, 2022 · 5 comments

Comments

@compmstr
Copy link
Contributor

Godot version

v4.0.beta2.official [f8745f2]

System information

Linux (Pop OS), NVIDIA GeForce RTX 2060, Video Drive v 470.141.03

Issue description

If you have a base class that extends Resource with some exports, and a Child class that extends that base class, the order of initialization on loading the resource seems backwards.

If the child class attempts to reference any values in the parent class during it's initialization, it will find that the parent class hasn't been set up yet.

The class init appears to be called with all default parameters (if the export values were passed here, I could pass it along to the parent constructor). Then a second step sets the exported values from the resource file. The second step appears to be called on the child class values before the parent class values.

I would expect that the parent class would have it's exported values set before the child class.

Steps to reproduce

  • Set up a Base class that extends Resource, that has at least one export
  • Set up a child class that extends the Base class, with it's own export
  • Have the child class try to reference one of the exported values on the Base class when setting the export value
  • Load a saved version of that child class
  • The base class value hasn't been set when you get to the point where the child class value is being set.

In the minimal reproduction product, I have an assert set up that will fail due to the parent class not being set up yet, so you should be able to just run it.

Minimal reproduction project

ResourceInheritBugTest.zip

@kleonc

This comment was marked as outdated.

@compmstr
Copy link
Contributor Author

If it helps, I can work around the issue by manually editing the resource file and putting the resource parameter values in the expected order.

They do revert again when I save, but I am able to get the code to run.

@vortexofdoom
Copy link
Contributor

I was just gonna do some digging on this and I did not find an official release for win64 where the MRP behaved "correctly" (I didn't test EVERYTHING back to alpha 1, but I did test it, and a few further back in order from the alpha 12 that @kleonc said worked). I might have done something incorrectly, but I think it may not be a regression?

@kleonc kleonc removed the regression label Feb 7, 2023
@kleonc
Copy link
Member

kleonc commented Feb 7, 2023

@vortexofdoom I've re-tested and indeed the behavior seems to be the same in both 4.0.alpha12 and 4.0.alpha14 (as well as in v4.0.beta17.official [c400205]). No idea how exactly I've tested it before but I'm assuming I've mistaken something and that's me who made something incorrectly in here. Sorry and thanks for the correction!

@YuriSizov YuriSizov modified the milestones: 4.0, 4.x Feb 27, 2023
@EAinsley
Copy link
Contributor

EAinsley commented Jul 3, 2024

The problem does not lay in the initialization order. The _init was called in expected order. The problem seems to be the value stored in .tres and .tscn files are in unexpected order. Other nodes also share the same behaviour. I'm not sure if this behaviour is a bug, since both .tres and .tscn files do not preserve inheritance structures, and you cannot tell if the property comes from base or derived class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: To Assess
Development

No branches or pull requests

5 participants