Godot Version
4.3
Question
Hi! I have a system meant to render my item resources in the game. There is a resource class that contains all the information about an item whether it be in the inventory, hotbar, or gameworld. I have a class that extends the ITEM resources called heat_item which is a subset of items that interact with my game’s temperature system. throughout the development of the inventory and Hotbar systems, I have passed heat_items into variables that required the ITEM resource type without issue; however, this is now not the case for the rendering of items in-game. Here is the code that I’m using for the item_overworld_container, which takes in an item resource and displays it.
@tool
extends Node3D
@export var item_stored : ITEM
@onready var sprite_renderer: MeshInstance3D = $"sprite renderer"
@export var threeD_item := false
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
if !threeD_item:
sprite_renderer.visible = true
sprite_renderer.mesh = QuadMesh.new()
sprite_renderer.mesh.material = StandardMaterial3D.new()
sprite_renderer.mesh.material.set_transparency(1)
sprite_renderer.mesh.material.albedo_texture = item_stored.ITEM_TEXTURE_GRID
sprite_renderer.mesh.material.billboard_mode = 2
sprite_renderer.mesh.material.cull_mode = 2
sprite_renderer.mesh.material.shading_mode = 1
sprite_renderer.mesh.size = Vector2(item_stored.ITEM_TEXTURE_GRID.get_width()/64, item_stored.ITEM_TEXTURE_GRID.get_height()/64)
else:
sprite_renderer.visible = false
var item_model = item_stored.ITEM_MODEL.instantiate()
add_child(item_model)
item_model.rotation = Vector3(90.0,0.0,0.0)
here is the ITEM class:
extends Resource
class_name ITEM
@export var ITEM_NAME : String
@export var ITEM_ID : int
@export var HOVER_TEXT : String
@export var ITEM_TEXTURE_HOTBAR : Texture2D
@export var ITEM_TEXTURE_GRID : Texture2D
@export var ITEM_GRID : Array[Vector2]
@export var ITEM_MODEL : PackedScene
and here is the heat_item class:
extends "res://Systems and Logic/item/classes/item_class.gd"
class_name heat_item
@export var heat_value : float
@export var passive : bool
I would understand if inheritance works differently in GDscript than in languages I am more familiar with; however, I’ve had no issue passing in heat_items in place of items before. Any help would be much appreciated.
PS. I tried setting the desired type to just a resource in general but that is unideal.