godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Improve User defined Classes #10094

Open mrjustaguy opened 4 months ago

mrjustaguy commented 4 months ago

Describe the project you are working on

FPS

Describe the problem or limitation you are having in your project

User defined Classes don't act anything like Built-in Classes (like Node3D, CharacterBody3D etc.)

User Classes add a regular old Script which has the downside of erasing any modified Class variable data when changing to a script that extends the User Class

Example: User Class - Vehicle has a variable Speed Vehicle Controller is a Script that extends Vehicle Assigning Vehicle Controller Script to the Vehicle resets Speed

This basically breaks any logic where you have to switch controllers around dynamically (like No controller - no Script, AI controller - AI script, Player controller - Player script)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a Class_Script that would hold the Script of any User Classes in essence making User Classes act like Built in Classes from the User's perspective

This would mean:

1) In the Editor User Classes would no longer have a Script defined, just a Class, albeit they'd have a link to the user script defining the class instead of built-in 2) Setting Scripts wouldn't Reset all User Class Variables

This resolves the issue in the example above as Class Variables are shielded from resetting when setting a script In the example above that would mean that much like when you set a script extending Node3D you don't lose your position, you wouldn't lose the vehicle's Speed

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Simply apply the Built-in Class logic to User Defined Classes, with the one difference of having a Variable for User defined Classes that would store the Class Script.

If this enhancement will not be used often, can it be worked around with a few lines of script?

You cannot fully workaround User Classes not behaving like Built-in Classes

Is there a reason why this should be core and not an add-on in the asset library?

This is a issue with Core

KoBeWi commented 4 months ago

Similar to #7905, which has an implementation pull request.

the downside of erasing any modified Class variable data when changing to a script that extends the User Class

That's a bug.