This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

Hello everyone,

I am trying to make a CCTV system for my game.
I have a few camera's placed in scene and a monitor to show what the camera's are seeing. I use a ViewportTexture for the monitor to show what the camera's are seeing.
My idea is that when you click on the monitor it switches to another camera.
The problem is that when I link the texture to the viewport in the editor, it works fine. But when I try do change the ViewportTexture by using a script, nothing happens.

This is an example that doesn't work for me (The file Cam1.tres is linked to the first camera and it's viewport):

onready var Cam1 = preload("res://Cam1.tres")

func _ready():
    material = $Monitor.get_surface_material(0)
    material.albedo_texture = Cam1
    material.resource_local_to_scene = true
    $Monitor.set_surface_material(0, material)

I have read that for it to work, the material and the texture must have local to scene set to true.
Also, when I run the game and look at the screen in the editor, it shows me there isn't a material applied.

Does anyone know how to fix this? (or know how to change the viewport textures by script)

in Engine by (15 points)

Please log in or register to answer this question.

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.