Call custom resource variable in a node, from another node?

Godot Version

4.2.1

Question

Hello all! I’m fairly new to Godot and have been enjoying it for the past week and a half. On my project I’ve started to delve into using custom resources. I’ll try and be brief:

I’ve made a Node that is my enemy, and then created a script for the resource in this case “class name = enemy_resource” within this script I have the usuals for an enemy: Health, Speed, Damage etc. now the node I have as a “Enemy Template” if you will has this custom resourced called in it as “@export var enemy: enemy_resource” within the custom resource there is a damage variable set to an integer @export var damage: int

I can setup different enemies with different damage but how can I place the custom damage I set for different enemies to affect the player scene? I apologize if this is confusing… feel free to ask me any questions and I do appreciate the help!

Bump12

“how can I place the custom damage I set for different enemies to affect the player scene?” - @BadHasher

What do you mean by affecting the player scene?
Are you asking how you can use your custom resource to hurt the player by the damage amount?

Yes! I have it to where the Player’s health is tied to a global (autoload) and the enemy template has a custom resource where it pulls the “enemy_damage: int”, I want to take that number and apply it to the player’s health.

Use this guide from Godot Docs.

Example:

var player_vars = get_node("/root/PlayerVariables")
player_vars.health -= 10

Solved! Thanks for the help I made a function in both the player and enemy and in the enemy I load a variable with the enemy resource damage then minus it from the global player’s health. The function should only play when the player enters the enemy’s area, therefore i’m able to instance the “enemy template” with loaded resource integers. This way I won’t be calling only 1 damage from the player scene.