can I change child node type in c#?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By egoal

Hi, so, I have a Character scene, like this:

Character: KinematicBody2D
| AnimatedModel: Node2D
| CollisionShape2D

then I made a NPC scene inherited from this:
NPC: Character
| AnimatedModel
| CollisionShape2D
| StayInPlace: Node

now, I want to set the model for my NPC (to, say “SorceressModel”), is it possible in c#? I think if I deleted the AnimatedModel then Instance a SorceressModel, named it as “AnimatedModel” could work, but I cannot do the deletion.


Also, currently, I have an alternative way when making my AI behaviour. like this:
I have a AIBase: Node to set the Character’s brain. And a StayInPlace: AIbase for the NPC. but I cannot change the type, so:

  • in Character, I just [Export] NodePath aiPath_;, then get it as AIBase in _Ready();
  • then in NPC scene, I instance StayInPlace node, then set to aiPath_ in editor.

This works for now, but is not that straight forward. and I think, by this, we have a aiPath_ member in each Character instance for one use only.