Hi, I've been having a problem recently, I want to change the color of a sprite in Godot through scripts and have tried looking at a lot of tutorials but whenever I try I get this error message "Invalid set index 'modulate' (on base: 'null instance') with value of type 'float'." I am probably making some dumb mistake but cant figure out what, pls help, thanks.

  • vmjcv replied to this.
  • You're passing cursorColor as a parameter to _process(). That parameter will override the variable declared above. Normally you don't call _process() yourself. It's called by the engine, and the parameter is a float that represents the elasped time in seconds since the previous call. Since there's no constructor for Color() with a single float parameter, that's why you get that error.

    The normal signature for that function is:
    func _process(delta: float) -> void:

    So you should replace:
    func _process(cursorColor):
    with:
    func _process(delta):
    or (better):

    #warning-ignore:UNUSED_ARGUMENT
    func _process(delta: float) -> void:

    CanvasItem.modulate uses a Color value, not a float.

    Also, you're using $Sprite where your node is named pixelSprite, so you should use $pixelSprite instead

    Thank you everyone for your responses! I have tried to implement what you guys have suggested but still get an error message saying "Invalid call. Nonexistent 'Color' constructor." does anyone know why this happens? It works if I use "$pixelSprite.modulate = color(1, 0, 0)" but is there a way to be able to input a hexadecimal color code and change the sprite color to that?

    You're passing cursorColor as a parameter to _process(). That parameter will override the variable declared above. Normally you don't call _process() yourself. It's called by the engine, and the parameter is a float that represents the elasped time in seconds since the previous call. Since there's no constructor for Color() with a single float parameter, that's why you get that error.

    The normal signature for that function is:
    func _process(delta: float) -> void:

    So you should replace:
    func _process(cursorColor):
    with:
    func _process(delta):
    or (better):

    #warning-ignore:UNUSED_ARGUMENT
    func _process(delta: float) -> void: