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

Exported custom Resource can be assigned any res type - no warning, and broken at runtime #39499

Closed
Flavelius opened this issue Jun 13, 2020 · 6 comments

Comments

@Flavelius
Copy link
Contributor

Flavelius commented Jun 13, 2020

Godot version:
3.2.1.stable.mono.official

Issue description:
Defined a custom Resource:

public class MyResource: Resource
{
  [Export] int testInt;
  public int TestInt => testInt;
}

then exported that resource in another class

public class MyNode: Node
{
  [Export] MyResource res;
}

it is possible to assign any resource type in the inspector.
No warning is printed and more importantly the resource can still be used at runtime acting like the declared type but dangerously and silently failing.

_Ready()
{
  GD.print(res.TestInt);
}

will print some random data
Steps to reproduce:
Run attached project

Minimal reproduction project:
ResBug.zip

@rsubtil
Copy link
Contributor

rsubtil commented Jun 13, 2020

This is well known, take a look at #6763 and #26162 and at godot-proposals

@Flavelius
Copy link
Contributor Author

Flavelius commented Jun 13, 2020

The first two ones are a bit different. The last one seems to want to address the problem.
The problem is not exporting the variables, that works somewhat, but that there's an underlying problem that the engine creates fake types that seem to (potentially dangerously) read wrong memory

@rsubtil
Copy link
Contributor

rsubtil commented Jun 13, 2020

I noticed now you're exporting a custom class. I don't think that's supposed to be possible ATM, at least in GDScript is not.

My advice for now would be to just use the base Resource for all export fields, and cast it to your custom type, until this feature is implemented. It's not pretty, but you're not alone in wanting this implemented, so it shouldn't be long before that happens.

I also found #27470, which I think is also happening in your project.

@Flavelius
Copy link
Contributor Author

Yes, thanks. When looking into it i read that this is the recommended way for now. But i still think this should be looked into, as filtering the dropdown is only a partial solution covering up that underlying issue which should not be happening in the first place (there must be some error prone magic going on behind the scenes)

@clayjohn
Copy link
Member

As @ev1lbl0w pointed out, this is a duplicate of #6763 and #26162 and godotengine/godot-proposals#18 please continue the discussion there.

I am closing this issue in favour of godotengine/godot-proposals#18. I am not dismissing your issue, you have pointed out a very annoying problem, but it is best for us to keep all discussions on a topic centralized.

@Flavelius
Copy link
Contributor Author

Flavelius commented Mar 13, 2021

I just wanted to keep this comment, that the issue is that there's no warning, no error and that it seems read some memory its not supposed to. I don't think it's in any way related to be able to export custom resources. There's likely a serious underlying bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants