How to load Viewport Texture by code ?

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

A viewport texture is define in Mob.tscn
I want it to be loaded in Main.tscn to some node :

var mob = Mob.instance()
var sprite =
sprite.texture = mob.get_node("Viewport")

How do you load a “dynamic” viewport texture as it can’t be done like loading a ressource file ?

sprite.texture = load("res://assets/some-texture.png")
:bust_in_silhouette: Reply From: Zylann

You simply get it from the viewport in code and pass it around where you want it to be:

sprite.texture = mob.get_node("Viewport").get_texture()

of course ! So obvious, I didn’t even try that one. :slight_smile:
Thanks a lot

atom | 2019-01-16 18:55