godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.14k stars 93 forks source link

Add a way for Objects to show a custom string representation in the Inspector dock #6214

Open rambda opened 1 year ago

rambda commented 1 year ago

Describe the project you are working on

trying to porting inkgd to godot 4.

Describe the problem or limitation you are having in your project

Uneasy to debug. Objects are shown as Object ID: ** (instance id) and there are too many of them. You'll have to click it to know what's inside the object. (Also clicking any object will trigger every properties of this object. It will trigger some error which won't happen when playing without debugging. Costs some time to handle these errors, not good for prototyping. )

It's better if an Object can show custom information in the inspector, like actual class name, and even some simplified info about its content.

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

The goal is this: (similar to Resource.resource_name) mockup

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

Some intuitive ways:

  1. Add a string property for Object to represent it (with custom information) in the Inspector dock. E.g. Object.inspector_string
  2. Add a virtual method. Override this method to customize the inspector string. Should return the given property's value, or null if the property should be handled normally. E.g. _to_inspector_string()

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

No.

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

It's core. Also I'm pretty sure a similar proposal has existed for a long time, as this behavior has existed since the day one debugger existed. But I just can't find it.

Calinou commented 1 year ago

Couldn't the _to_string() method be reused for this?

KoBeWi commented 1 year ago

It displays as "Object ID: xxxxx", because it's property of type ObjectID, not Object.

rambda commented 1 year ago

Couldn't the _to_string() method be reused for this?

I ignored the existence of _to_string() because I myself, in practice, often use print(object) to output extremely long strings in Output that fully indicate the current state of the object, because it is convenient. But the inspector dock has limited space. On second thought, it's better to use _to_string() to do this. I can define my own get_debug_string()

IcedQuinn commented 1 year ago

Just ran in to this problem on a similar task. Using objects is cleaner than dictionaries but then the debugger unhelpfully shows object IDs.

andymeneely commented 9 months ago

Glad someone wrote this up! 100% would be awesome. And I like the idea of inspector_string because it makes it clear what it's for. At first I was confused by resource_name until I read the docs.

donn-xx commented 1 month ago

I think I also ran into this. I am working with Resource classes and instances. When I print them, I get things like Resource#-9223372003401005752, but in the debugger it's Object ID: 922....xxx where xxx is not the same ending as 752.

In other words, I can't tell if this is the same object (in the debugger vs the print outs) or some kind of duplicate. It's confusing.

KoBeWi commented 1 month ago

You can inspect the object in debugger and see its path.

donn-xx commented 1 month ago

You can inspect the object in debugger and see its path.

Better would be—how can I print the ObjectID for a given object (like a Resource) such that it will match what the debugger is showing. The path thing is too many clicks away.

mikemike37 commented 3 weeks ago

A default could be to replace "Object ID" with the class name (if available)?

... but I'd really appreciate the ability to customise the inspector string representation of the object, as described above.