I’m trying to make a modular npc system because I’d like to add tons of types of npcs easily. By npcs I’m also including enemies, etc kinda like entities so to say.
Currently I have Hurt/Hitbox and attack components with a system that tracks the condition of the npc’s body parts. However I tried storing the information for the body in a resource so that in theory I could just use that resource for the same npc type,
but then I realised every npc that uses that same resource file will share the same body condition. Is there a way for each instance of the npc to still have their own information while still using a resource file to declare an npc type? Because I would like the ability to save the condition of npcs and make them persistent. Or is there a better way of doing what I’m trying to do.
The local_to_scene property will not make the resource unique for that scene (maybe using duplicate() could solve it).
Think of the Resources only for store the data. If you want to change it (like decreasing health when hit), you can define the variables in the node that will handle this information and then assign the value from the Resource file to that variable.
var health:int
func initialize() -> void:
health = resource.health
From there, you can manipulate the data that will afect only that exact NPC.
ok, if you are not forgetting to assign a resource to BodyParts, maybe the problem can be that you are calling this in _init() function. This method happens really early in the tree, maybe the BodyParts isn’t ready yet.
For these things, I reccomend using a method for initialization of the node. Then, in the parent (or anywhere else that is instantiating this node) you call that initialization function.
func initialize():
parts = BodyParts.parts
In the parent, you call initialize().
PartsComponent.initialize()
This way, you have more control in the initialization of the the scripts and its content.
That fixed the error. But all of the npc’s still share the Body Parts conditions. So I’m back at step 1. I think this problem isn’t part of my original question anymore since you guys have told me the solution but I’m the one having problems implementing it
Can you describe in more details how are setting up this resources and scenes that will use it? Maybe a link with a project sample so we can analyze it?