Trying to access a shader parameter with a function call inside a Area2D node.

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

I currently have a world node that I run my game from. Inside the node I have setup an Area2D node that checks whether my KineticBody2D has entered or left the area. Once these checks happen, I make a camera switch from the player camera to one that is a child of the Area2D node.

The Area2D camera child node has a CanvasLayer and a ColorRect attached to it as children. The ColorRect is a shader effect that I have made with the help of a tutorial that has parameters such as cutoff that can be used to animate a screen fade out from black to what the camera sees. I currently have access to the CanvasItem visibility bool that I can turn off or on depending on the triggers which turns my screen black. I can’t however gain access to the cutoff value parameter that is part of the shader code which goes from 0 to 1, which I would like to lerp in order to create a smoother transition so that the changing of cameras wouldn’t be as jarring.

extends Area2D

func _on_Room_body_entered(_body: PhysicsBody2D) → void:
print(“area entered.”)
get_node(“Camera2D”).current = true
get_node(“Camera2D/CanvasLayer/ColorRect”).visible = true
#get_node(“Camera2D/CanvasLayer/ColorRect”)

func _on_Room_body_exited(_body: PhysicsBody2D) → void:
print(“area left.”)
Player.get_node(“Camera2D”).current = true
get_node(“Camera2D/CanvasLayer/ColorRect”).visible = false
#$Player/Camera2D/CanvasLayer/ColorRect.get_material().set_shaderparam(“Visible”, false)
#Player.get_node(“Camera2D”).smoothing_enabled = false

func _on_ColorRect_visibility_changed():
pass

I am fairly new to Godot so maybe I still haven’t completely grasped the node -based workflow and I just need to organize them better in order to achieve the result I am after.

This is my first time posting a question here on godotengine, so I do not know how to upload a screenshot from my computer to better illustrate my situation, but I hope this is enough information to at least give some sort an idea of what I am dealing with.

Any help would be appreciated.

Hi,
this isnt to solve with the information you given.

How are your node arranged? What does the shader look like? In wich slot is the does the material reside?

Lets start here … do you get an error when executing this line?

$Player/Camera2D/CanvasLayer/ColorRect.getmaterial().setshaderparam("Visible", false)

what does the error state?

klaas | 2020-09-25 07:48