Godot Version
Godot 4.2.1
Question
I am new to Godot and trying some smaller projects based on existing games to help myself learn. Currently I am trying to build a Pokemon battler, which would be a game that allows me to preset different custom Pokemon for myself and an AI opponent, and have us battle like a normal game.
Currently, I have a Battle scene, which is attached to a script to handle the battle process. This script exports and Opponent field, which I can assign a predefined resource to. This simple base class will be extended to subclasses such as a battle against a wild Pokemon, or single or double battles against Trainers. Opponents essentially export a single array called their Team, which I instantiate individual Pokemon. These Pokemon are also Resources, and this class represents an actual individual Pokemon in the world or on your team, as opposed to the PokemonSpecies resource which contains data shared by all pokemon of the same species.
This is my problem: The Pokemon on my opponent’s team do not have data related to their base stats, such as speed, attack, health, etc that should be calculated when the Pokemon is created. Since this Pokemon Resource is not a Node, and is not a part of the scene tree, I can’t do these calculations in _ready(). When I moved this logic to an _init() function, I found that the details I had specified in my editor were not present in the debug session when the code ran, i.e. the Species of these pokemon are null even though I have set them in the editor.
My question: What is the right way to fix this? Is there a Godot preference? I’ve come up with some potential solutions but I was hoping there was another lifecycle method I don’t know of, or an annotation like @onready that I can add to the _init() function.
I could 1) Replace many of my resources with nodes, add the _ready() function, and have an opponent’s Pokemon be nodes in their scene tree, but this would make each individual opponent much more time consuming to set up I think, and it would require me to add logic that knows about the scene structure, which I thought I should avoid. Currently, I have one battle scene and many opponent resources, rather than many opponent scenes that would be added to a base battle scene.
Or 2) I could add logic which calls my own initStats() function on every Pokemon in the scene from the Battle script. This would call a similarly named function in my opponent class, and it would be up to each specific opponent subtype to call this function manually on every Pokemon they are responsible for.
Which approach would you recommend? Have I overlooked an easier option? Should individual of a species in the world be represented as Resources or Nodes?
I will add some relevant code/pictures in a comment, it seems easier to do that way.