QodotPlugin / qodot-plugin

(LEGACY) Quake .map support for Godot 3.x
MIT License
960 stars 70 forks source link

Declaring a point entity that uses a "Scene file" breaks runtime generation on exported builds #110

Open haekb opened 3 years ago

haekb commented 3 years ago

Oof that's a title.

Basically my game uses runtime map generation, and it's very neat! (So thank you!) I've ran into a bit of a problem (but also found a work-around.)

Here's my old point entity setup: image

It worked great in-editor, however once I did a test export I kept getting the error message:

ERROR: Edit state is only for editors, does not work without tools compiled.
   At: scene/resources/packed_scene.cpp:1695

It would point to line 437 of qodot_map.gd. Which actually is the result of the above error being triggered on line 432.

                elif entity_definition is QodotFGDPointClass:
                    if entity_definition.scene_file:
                        node = entity_definition.scene_file.instance(PackedScene.GEN_EDIT_STATE_INSTANCE)

A work-around I found was to just create a point entity using a "Script class" instead. This class would just load the scene and add it as a child like so:

public class PlayerStartEntity : Node
{
    public override void _Ready()
    {
        var scene = GD.Load<PackedScene>("res://prefabs/Player.tscn");
        AddChild(scene.Instance(), true);
    }
}

Let me know if you need anymore information!

Shfty commented 3 years ago

This is caused because GEN_EDIT_STATE_INSTANCE is an editor-only parameter that I assumed it would fail in a friendly way, but throws an error and crashes the script instead.

Replacing line 432 of qodot_map.gd with the following should fix it:

var edit_state
if Engine.is_editor_hint():
    edit_state = PackedScene.GEN_EDIT_STATE_INSTANCE
else:
    edit_state = PackedScene.GEN_EDIT_STATE_DISABLED
node = entity_definition.scene_file.instance(edit_state)

Need to make sure the new version of QodotMap behaves correctly in this respect.