Choose Specific Enemy Type as Custom Resource on Marker3D Scene

Godot Version

v4.5.stable.official [876b29033]

Question

Hi all,
I want to be able to drag in a Marker3D-based scene onto my level scene, then select a particular Enemy type scene that the Marker3D will spawn.

My thought was to use custom resources, but do I need a custom resource for each enemy type, or could I simply add every enemy type to the Marker3D scene, then choose it from there?

It seems to me the best approach is making a resource for each enemy, but I wanted to confirm my understanding:

  • Using a resource this way would prevent having Godot make copies at runtime
  • If I wanted to add/change functionality, I could do so in the resource and it would apply to all markers using the resource (thus some flexibility)

Just to provide as much detail as possible, this is my current approach:

  1. Create an enemy scene
  2. Create an EnemyResource type that takes the new enemy scene as its export var
  3. Drag and drop the resource I want spawned on the Marker3D scene

My hesitation here is that I could always just have an export variable on the Marker3D scene that takes the inherited enemy class and choose that way. Are resources prefereable?


I think the approach you should take is have an exported variable of type PackedScene be included in your Marker3D, drag over the enemy scene you want spawned by your Marker3D in the editor, and then have your Marker3D do whatever you want with the enemy scene. Rather than put your scene in a resource and drag the resource over to do the same.

You could then name each Marker3D to easily tell all your Marker3Ds apart from each other based on what scene you put in.

And I think it would be in your interest to make copies at runtime, otherwise wouldn’t all the enemies share the same data? I.e you interact with one enemy and it applies to all of those enemies that use their assigned resource. Bottom line I don’t think resources are preferable here.