|
|
|
|
Reply From: |
Steven Vroom |
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.
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
ext_resource as id=1
and add 1 to every other ext_resource '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!
Dlean Jeans | 2019-01-03 10:15
Worked perfectly, and was easier than expected. Thanks!
JamesFrankel | 2020-08-01 00:44
As an additional step to what Dlean Jeans said, in Godot 3.4.4 you are gonna wanna delete the type
(or instance
) of any node
that’s also in the inherited scene, for example, if you have a hurtbox node both in enemy.tscn and in damageable.tscn, and you want both nodes to be one and the same in enemy.tscn, you’ll have to change
[node name="hurtbox" type="Area2D" parent="pivot"]
to
[node name="hurtbox" parent="pivot"]
in the enemy.tscn file.
Otherwise both nodes will coexist in a weird state where neither displays the changes enemy might have applied to it.
Note that this will also reorder the nodes, as the inherited nodes take precedence over non-inherited nodes. That is:
- if all nodes are non-inherited and they have no set
index
in the file, they will be listed in the order they are mentioned
- if some nodes are inherited and others are non-inherited, and they have no set
index
, the inherited nodes will be listed first
- if a node has a set
index
([node name="hurtbox" parent="pivot" index="3"]
), then its order will be respected regardless of whether it is an inherited or non-inherited node
So if you have non-inherited nodes that should be higher up in the childlist of the node, you’ll have to either set their index
in the file by hand or reorder them in the editor.
Saving the file in the editor for the first time will set indexes
for every node
in a way that reflects the way the tree was rendered in-editor when it was saved, it will also update the load_steps
and remove unused resources. None of this will break or alter the scene.