#Instantiating a custom PackedScene object

1 messages · Page 1 of 1 (latest)

stiff needle
#

Using Godot 4.3.stable and C# for everything.

I have a custom file format from very old assets (90s, not Doom) which I know 99% of the file format. Given copyright stuff, I don't want to embed old game assets in my project. But I would like to allow people copy them into a specific directory and be able to load them.

Through ResourceLoader.AddResourceFormatLoader I am able to open those files in the editor, and they show up and can inspect them. But when I try to make them show up in a new scene, its impossible unless I am running the game. I would like them to show up in the editor. The resources I am dealing with are textures/materials/meshes/meshes_with_bones/animations. What I have tried:

  • In game, I can use those resources to create a "scene" (sub-node-tree) and add them to the current tree. This works, but I want to go further.
  • In editor, I can open the resources on the Inspector Panel, but I can't do anything with them, like create an instance in the current editor, and using them in a new thing is quite cumbersome. Copy pasting paths is hard
  • In editor, I converted the "character" models with animations to a PackedScene, but they still can't be opened or instantiated.
  • In editor, the C# class that derives from PackedScene has an Instantiate method that can create what I need, but I can't still do anything.

This sums up my path more or less, and I am lost. I know it is not a common problem.

Please help

stiff needle
#

I have a plugin to enable the resource format

#

Can @tool embed in the editor under

#

I have a hierarchy of resources

real rose
stiff needle
#

Because @tool seems only accessible from the Project menu. Not much experience with it

real rose
stiff needle
#

Ok, so I can have an EditorScript that I can run while editing a GDScript file (not with C#) and that will run some code in the editor

#

how can I reference a resource inside a resource in the editor? The script will look like

((load("res://path/file.xxx") as PackFile).Files.Get("file.actor") as Something).Instantiate()
#

In my case is multiple levels more

stiff needle
#

Would it be interesting to explore EditorSceneFormatImporter ?

#

Or EditorResourceConversionPlugin?

turbid crown
# stiff needle Using Godot 4.3.stable and C# for everything. I have a custom file format from ...

The resources I am dealing with are textures/materials/meshes/meshes_with_bones/animations
It seems like is something you don't want to modify in runtime and most likely you want to have optimized on the exported game. You need to import them

In game, I can use those resources to create a "scene"
And you probably want to import them as packedscene, just like godot does for models.

You would use a EditorSceneFormatImporter for that purpose, since you don't want just plain data, but certain nodes generated from that data

turbid crown
stiff needle
#

I have the files loading in the editor, I just can't use them in a scene without either a @tool or something similar. I was expecting the editor to be able to instantiate packed scenes somehow

turbid crown
#

You're providing a method to read those, you're not including them at the end

stiff needle
#

Aren't assets that are imported then included when you export the game?

turbid crown
#

Yes, but you don't need them. Once you're done just remove them

stiff needle
#

Ahhh, and the game will import them at runtime if needed

turbid crown
#

First... Try to import them in editor

#

The runtime process is very different

#

The game doesn't have access to Editor* stuff

stiff needle
#

I am importing them currently in the editor through ResourceFormatLoader, can display meshes/textures inside the editor, but I can't instantiate a model for example

#

I thought I could do that instantiation through some tooling editor, I have code to do the instantiation in runtime

#

Thanks! I will try this path and see where it goes

stiff needle
#

Does this support 1 file to many scenes?

turbid crown
#

The importer? Yes

#

In runtime is another story

stiff needle
#

runtime I can manage 🙂

#

but import scene function can only return 1 thing

#

So, I have an EditorImportPlugin which builds a resource containing everything, what I have found is that EditorSceneFormatImporter takes a Resource and creates an scene from it, but given ImportScene needs a path, looks like I can return only one scene

stiff needle
stiff needle
turbid crown
stiff needle
#

but resource importer doesn't allow me to instantiate objects into the scene

turbid crown
#

I'm curious if resource importer let you create the scene and link those

stiff needle
#

Work is going to make me unavailable for a couple weeks

#

I will test and try as much as I can, but can't guarantee anything

stiff needle
#

I have managed to make the scene importer show the advanced import scene and show all the models in there, but then I click reimport and files gets processed again. Now, I go and click on the file in the resource list, and click instantiate and a single Node3D appears without any of the content of the file.
Also docs for EditorSceneFormatImporter are virtually non-existant.

The example above returns a Node3D as root, but instantiate requires a PackedScene I guess. This is all a bit confusing tbh

#

I guess all my confusion comes from the fact that it is not clear to me what importing precisely means and its not well explained in the docs.

  • Does it mean that it is imported into the editor and it can be referenced by some scenes, so when I export those scenes, they will be bundled?
  • Does it mean that when something is imported, the source file is going to be ignored and only pre-processed resources are included in the runtime?
    How does affect importing regarding runtime?

This all gets a bit more confusing if you add ResourceFormatLoader and ResourceSceneFormatImporter.

Been re-reading https://docs.godotengine.org/en/stable/tutorials/assets_pipeline/import_process.html but its all unclear

turbid crown
#

Sounds complex

stiff needle