-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Custom resources return null when running the scene, despite being shown as existing in the editor. #74475
Comments
I believe I'm having this issue as well. When you run your test project under the debugger, are you getting some |
The instances cannot be default constructed which causes bugs somewhere, not sure why, but at minimum the error needs to be more clear. But as a workaround you need to make the types have default arguments: func _init(angles_x: NumberRange = NumberRange.new(), angles_y: NumberRange = NumberRange.new()):
func _init(min: float = 0, max: float = 0): |
Duplicate of #67059 |
I get no errors no, the resources just become null as soon as I run the scene. |
I get errors when I run your project |
This does fix it! Thank you for letting me know 💖 |
Following the chain from this did indeed help me resolve my issue which was of course the one mentioned, but I agree it should absolutely be made more clear to users that they shouldn't be writing _init with parameters for anything that will be instanced by/in a scene. I ended up deleting a lot of what was effectively unnecessary boilerplate (admittedly, it was useful back in 3.5 because back then you couldn't export custom resource types) and then it just worked once I'd got rid of enough of the stuff that was relying on doing stuff in initialization. Perplexing though as it wasn't obvious and I didn't find a note about it in documentation either. |
That's what the proposal godotengine/godot-proposals#1513 is about |
Godot version
v4.0.stable.official [92bee43]
System information
Windows 10,
Issue description
I have two custom resources that exist as class scripts in my project, and I can select them just fine in the inspector and set parameters however I like. And their
resource
dropdown tells me that they're being saved properly in the scene with a proper path.BUT When I run the scene, all resources that I have changed in the inspector are treated as
<null>
, while all the resources of which I didn't change the value in the editor retain their default code values. Am I doing something wrong, or is Godot being silly?Here is the code for both of my custom resources:
and here is the
@export
variable they're used by:the
@export
variable above is recognized just fine, but if I dare to change it, it just outputsnull
Steps to reproduce
@export
variable in another script attached to a random node with a default value, and add a call the resource with a null check and a printMinimal reproduction project
This project is the one that has the issue, it's only a scene with a few interaction points and a
print
already present where the issue occurs. Clicking on the goal in the blue area of the map should cause the print to start printing<null>
repeatedlyexample_project.zip
The text was updated successfully, but these errors were encountered: