GDScript: How to extend a built in resource, override a method, and have it work in the inspector?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Bryce

If I have a GDScript like this that extends the built in OpenSimplexNoise:

extends OpenSimplexNoise
class_name OpenSimplexNoiseCurve

export(Curve) var curve

# override parent method
func get_image(width: int, height: int):
    
    print("get_image override")
    
    # call parent method to get noise image
    var img:Image = .get_image(width, height)
    img.lock()
    
    # loop through pixels and apply curve
    var c: Color
    for x in width:
        for y in height:
            c = img.get_pixel(x, y)
            c.r = curve.interpolate(c.r)
            c.g = c.r
            c.b = c.r
            img.set_pixel(x, y, c)
    
    img.unlock()
    
    return img

I can call the get_image() method from within my own script and it works as expected.

But if I add an OpenSimplexNoiseCurve resource to a NoiseTexture on a Material via the inspector, it doesn’t print the message, change the image output, or throw an error.

Is this a bug, or will built in Resources like NoiseTexture only call the base method of a property Resource, and not the one overridden in GDScript?

Does anyone have more info on this?

Bryce | 2020-03-09 21:54

Adding a comment again to hopefully bump this and get an answer.

Bryce | 2020-04-06 03:17

:bust_in_silhouette: Reply From: rustyStriker

have you tried using the tool keyword? here is an example

Yeah I do switch scripts like this to tool mode for testing, but that isn’t the issue here.

In tool mode the default OpenSimplexNoise properties in the inspector will update the texture on the material. And I even have a_set() method override multiplying the noise period by another exported property in the inspector (_set() is not called by another built in resource, but by the editor I think).

The issue is that a NoiseTexture resource set as the albedo of a material wont call the overridden get_image() method of my extended noise class, it calls the base method. I want to know if this is intended or a bug.

Bryce | 2020-02-17 20:28