I tried to load images to a sprite by stating the image path.. It didn't work . SO - 1) Is it possible to do such a thing ? 2) If YES where's the problem with my code ?

Here's the project screenshot --

As you can see It's resulting in a Null Instance.

Here's the code (incase the image didn't load) --

extends Node2D

#Image path in file_system
var  curMap_path

#Node alias for the Sprite containing the image.
var curMap

#A variable meant to be random(ed)
var bg_value

func _ready():
	
	curMap = get_node("Background/ParallaxLayer/Sprite")
	
	randomize()
	
	bg_value = randi() % 3+1
	
	if (bg_value == 1):
		curMap_path = "res://Assets/Map/Night_sky_Blue.svg"
		
	if (bg_value == 2):
		curMap_path = "res://Assets/Map/Night_Sky_Black.svg"
		
	if (bg_value == 3):
		curMap_path = "res://Assets/Map/Night Sky_Green.svg"
		
	curMap.texture.resource_path == curMap_path

Hi,

Try something like this in the Map.gd file:

$Background.ParallaxLayer.Sprite.texture = preload('res://the_path_to_your_file')

Should work with Godot 3.

4 years later