The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

I've been trying to load in a new ShaderMaterial thru script but I think I'm doing it wrong :(
enter image description here

here's the actual code:

extends MeshInstance

onready var dummy_cam = $DummyCam

onready var mirror_cam = $View/Camera

onready var SM =

onready var W

onready var mat = self.get("material/0")

func _ready():






View.size = Vector2(2000,1000)

func updatecam(maincam_transform):

scale.y *= -1

dummy_cam.global_transform = main_cam_transform

scale.y *= -1

mirror_cam.global_transform = dummy_cam.global_transform

mirror_cam.global_transform.basis.x *= -1

on top of that I still have yet to find a way to ".set()" this:
enter image description here
so It could change paths when I try making more of this in a future scene

in Engine by (66 points)

1 Answer

+1 vote

Godot is telling you mat is null. null means the variable contains nothing.

onready var mat = self.get("material/0")

onready code will run just before your _ready function. You did not assign material 0 at this time, so mat will contain null.


Later you are assigning material 0, but the mat variable will still be null. You have to write mat = self.get("material/0") AFTER you set the material slot, or better, just write mat = SM.

Also, you don't have to use set or get. Properties are described in the doc to do this. Just write mat.shader = load("res://Mshader.shader"), or set_surface_material(0, SM) (no need for self either).

by (29,360 points)

so I got rid of "mat" all together:
enter image description here

I still couldn't instantiate a new ShaderMaterial to "material/0"

oh wait my bad I'm suppose to use setsurfacematerial(0, SM) brb

enter image description here
Still didn't work :( what am I doing wrong :((

In your last screenshot, you are showing the Local scene tree. This is the scene as it is before it runs. If you want to see properties of your node while it is running, select Remote at the top of the scene tree (and wait for a bit, it can take some time to update).

Also, you are getting an error later in your script. You are calling load with a ViewportTexture, but load expects a path to a resource instead.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.