+1 vote

I have an enemy scene that doesn't inherit anything, but now I want it to inherit a scene called damageable. How do I change the inheritance of the enemy scene?

in Engine by (38 points)

Don't know if will work as you expect but try making a new scene that inherits "damageable" and merge with your actual "enemy" (right click on the tree you have the option to merge scenes),.

That sadly didn't work.

3 Answers

+3 votes
Best answer

In the end I had to hand edit the scene file to change the inheritance of the scene. A quick run down of what I did:

added 1 to the loadsteps in

[gd_scene load_steps=3 format=1]
                     ↓
[gd_scene load_steps=4 format=1]

added a line to load the resource to inherit from

[ext_resource path="res://scenes/objects/damageable.tscn" type="PackedScene" id=1]

added 1 to all the other ext_resource's id and the lines where these are used

[ext_resource path="res://scripts/objects/enemy.gd" type="Script" id=1]
                                                                     ↓
[ext_resource path="res://scripts/objects/enemy.gd" type="Script" id=2]

&

script/script = ExtResource( 1 )
                             ↓
script/script = ExtResource( 2 )

and I removed the first node's type and replaced it with the inherited scene

[node name="enemy" type="RigidBody2D"]
                   ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
[node name="enemy" instance=ExtResource( 1 )]

Maybe I could've just given the scene to inherit from the last id, but I was afraid that that might somehow bite me later on.

by (38 points)

For someone stumbling up on this in the future (I'm using Godot 3.1 alpha 5),

You don't actually have to add the PackedScene extresource as id=1 and add 1 to every other extresource 'cause that would be too fiddly if you have dozens of nodes. Instead add it to the bottom with the next id available. Also no need to increase the load_steps.


To illustrate,
say you have 6 ext_resources in your .tscn file.
Add this but with id=7 instead of id=1,

[ext_resource path="res://scenes/objects/damageable.tscn" type="PackedScene" id=7]

Then edit

[node name="enemy" type="RigidBody2D"]

to

[node name="enemy" instance=ExtResource( 7 )]

You're done! :D

Worked perfectly, and was easier than expected. Thanks!

+1 vote

I'm afraid you can't in the actual stand of Godot Editor. You can only replace the root node with an standard node.

by (698 points)

That's annoying, sounds like a normal capability to me.

+5 votes

One way to do this through GUI is by merging scenes.

I did this by inheriting a new scene from the parent, merging it with the scene you want to be a child scene and then saving it by replacing at the place of that scene, so it does not break any links.

For example:
Parent scene : Machine
Wannabe Child scene : Aeroplane
inherited new scene (from Machine) : new_aeroplane (not yet saved)

Now merge Aeroplane with newaeroplane, (from newaeroplane scene)

Save new_aeroplane as Aeroplane to preserve links

by (24 points)

This way is safer!

This seems to work quite well.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.