Resource path is being passed but when Accessed it returns null

Godot Version

Godot 4.3

Question

This is really bugging me. So as it goes im writting a script where im tryna pass through a custom Resource (Cards) in which will allow me to be able to assign values onto each new card instance. But for some reason when I try getting the values that has been pass through from the resource the path itself gets passed through but none of the data assigned to it does. Which it gives me this error:

Invalid access to property or key ‘outline_texture’ on a base object of type ‘Resource(Cards)’

So here’s the script that’s causing the issue:

extends Control

@onready var outline_texture_display : TextureRect = $VisualUI/Outline
@onready var background_texture_display : TextureRect = $VisualUI/Background

var card_ability
var card_ability_description

func assign_card_values(card_resource : String):
	var loaded_path = load(card_resource)
	
	print("Resource Path: ", loaded_path.resource_path)
	
	# Directly access the resource properties
	if loaded_path.outline_texture != null:
		outline_texture_display.texture = loaded_path.outline_texture
		print("Assigned outline texture: ", loaded_path.outline_texture)
	else:
		print("Error: Resource outline_texture is null.")
	
	#outline_texture_display.texture = outline_texture
	#background_texture_display.texture = resource.card_display
	
	card_ability = loaded_path.ability_Type
	card_ability_description = loaded_path.description

Here is the custom Resource:

extends Resource
class_name Cards

@export var card_display : Texture
@export var card_outline : Texture 

@export_category("Card Properties")
@export_enum("Hearts", "Diamonds", "Spades", "Clubs") var card_type : String
@export_enum("None", "1", "2", "3") var ability_Type : String
@export var description: String

signal used(ablity)

func display_card() -> String:
	return "Word"

## TODO: Have it so when the player choses to use this card then the function will fire
func use_card():
	emit_signal("used", ability_Type)

And here is the script that assigns the Resource Data to the Card Manager:

extends Control

var held_deck : Array[Control]
var held_card : Control

@onready var card_template = load("res://Scenes/card_scene.tscn")

## TODO : Move this into its own hand Node Once set up
func _ready():
	add_card("res://Resources/Card/Card Data/Card_test.tres")

func add_card(added_card : String):
	if added_card == null:
		print("Error: The card resource is null.")
		return
	
	var card_instance = card_template.instantiate()
	card_instance.assign_card_values(added_card)
	add_child(card_instance)
	held_deck.append(card_instance)
	
	card_instance.card_button.connect("hover", Callable(self, "assign_held_card"))
	card_instance.card_button.connect("use", Callable(self, "use_card"))
	
	## Modify the hand's size so it adds to the visual deck
	pass

Keep in mind im still quite new to Godot so if you can either explain or point me in the right direction that’ll help me a lot

So I’m an idiot and very sleep deprived. I’ve found the issue which was that I assigned the wrong name…

But it goes to the second issue that I was having. When assigning the recTextures texture but when used it says it’s null:

Invalid assignment of property or key ‘texture’ with value of type ‘CompressedTexture2D’ on a base object of type ‘Nil’.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.