Hi everybody, I'm trying to figure out how to make a game moddable and especially how and where to install new mods (.PCK files) in the compiled game and how the main code has to be developed to be able to read new mods.

Step 1 Create and compile a project My question is: how can the project find and read new MODS? Is it fine if I create a kind of directory listing and let the program "list" all the ".tscn" within?

Step 2 Let users to install new mods How can I make directories able to get new mods? For example. I have a dir "Enemies" with few subdirs. Is it possible to let mod installation (with any installer program) creates new dir and copy the new mods on it?

3 Execute new mods func _your_function(): ProjectSettings.load_resource_pack("res://mod.pck")

Now one can use the assets as if they had them in the project from the start

var imported_scene = load("res://mod_scene.tscn")

Based on the Godot docs I'm writing this function. Everything works fine until it loads the pck file but it doesn't execute the loaded .pck. Any advice?

func LoadModLevel (modName):
	
	# Load the selected Mod/Scene
	ProjectSettings.load_resource_pack("res://mods/" + modName)
	var next_scene = load("res://mods/" + modName)
	print ("res://mods/" + modName)
	
	# Delete all subnodes and clean the main node/scene
	for i in range(0, get_child_count()):
		get_child(i).queue_free()
	
	# Attach the loaded scene to the current main node
	add_child(next_scene)

I only have very, very limited experiencing loading .PCK files with the intent of making mods. Are you sure the LoadModLevel function is being called correctly? Maybe that is causing the issue?

You may want to ask on other Godot communities, as users there may know more about making games in Godot mod-able.

@TwistedTwigleg said: I only have very, very limited experiencing loading .PCK files with the intent of making mods. Are you sure the LoadModLevel function is being called correctly? Maybe that is causing the issue?

You may want to ask on other Godot communities, as users there may know more about making games in Godot mod-able.

ok but so what kind of file can I distribute with the game as addons? Even in the compiler, I see the option to make PCK files

I believe you can load .pck and .zip files in Godot, so probably you want to try those first. The .pck and .zip files should be able to store anything that a normal Godot project can use without any issue. I think the documentation for exporting PCKs mentions this, but I have not read it in full in awhile.

@TwistedTwigleg said: I believe you can load .pck and .zip files in Godot, so probably you want to try those first. The .pck and .zip files should be able to store anything that a normal Godot project can use without any issue. I think the documentation for exporting PCKs mentions this, but I have not read it in full in awhile.

Do you what? I'm trying to add a simple scene , a standard project file .tscn into the scene using this code and it doesn't work, So I think the problem it is not about loading a pck but add something to the scene

    	var next_scene = load("res://mods/Crab.tscn")
    
    	# Attach the loaded scene to the current main node
    	#get_tree().get_root().add_child(next_scene)
    	add_child(next_scene)

Nothing happens, where is the error? then , if I use an instance like

var next_scene = load("res://mods/" + modName).instance()

I got an error "nulled instance"

Are you sure the scene exists in the loaded pck file? When you load a pck file, it places all of the resources in the EXACT same location as it was in the mod. So, for example, if you have a project with the following file structure:

  • res://
    • scenes
      • test_scene.tscn
    • assets
      • test_asset.png

Then after you have loaded the PCK from the project with the file structure above, you could access test_scene.tscn using code like load("res://scenes/test_scene.tscn"). (Again, this is from my limited understanding)

Just forget the PCK file for now man. I've just created a simple Node2D scene with a sprite, nothing else. Saved as tscn file And I cant add it to the main project at runtime, cant understand

@"K-Storm-Studio Ltd" said: Just forget the PCK file for now man.

Alright...?

I've just created a simple Node2D scene with a sprite, nothing else. Saved as tscn file And I cant add it to the main project at runtime, cant understand

Where is the tscn file saved? How are you adding it to the project at runtime?

Just forget the PCK file for now man.

Oi, I get the frustration but keep it nice. TwistedTwigleg is trying to help you out here and has given some perfectly good information.

To load in a scene and add it to the calling node you would do the following:

var some_scene = load("res://your_path/scene_name.tscn") # Load the actual scene 'blueprint'
var instance_from_scene = some_scene.instance() # Create a node from this blueprint
add_child(instance_from_scene) # Add the node to our active scene and tell it to process

It seems like you had most of this. If you are getting an error then you are doing something wrong. The only place I can see you going wrong, as TwistedTwigleg has implied, is that you are entering the wrong path to your scene.

You gave us this:

var next_scene = load("res://mods/" + modName).instance()

What is modName at this point? Double check that the variable is correct and that the path exists in your local project directory.

EDIT: Just in case this is what you are trying, let me address it. If you are attempting to create a .tscn file separate from your compiled project and load it in as a mod then this isn't how you do it. You have to 'compile' the scene as a PCK (same way as you compile the whole project) and load it in that way.

res:// references the 'location' inside of a PCK file and not the actual file system that your game is launched from. Kind of, best way I can think of describing it.

@Binsk said:

Just forget the PCK file for now man.

Oi, I get the frustration but keep it nice. TwistedTwigleg is trying to help you out here and has given some perfectly good information.

To load in a scene and add it to the calling node you would do the following:

var some_scene = load("res://your_path/scene_name.tscn") # Load the actual scene 'blueprint'
var instance_from_scene = some_scene.instance() # Create a node from this blueprint
add_child(instance_from_scene) # Add the node to our active scene and tell it to process

It seems like you had most of this. If you are getting an error then you are doing something wrong. The only place I can see you going wrong, as TwistedTwigleg has implied, is that you are entering the wrong path to your scene.

You gave us this:

var next_scene = load("res://mods/" + modName).instance()

What is modName at this point? Double check that the variable is correct and that the path exists in your local project directory.

EDIT: Just in case this is what you are trying, let me address it. If you are attempting to create a .tscn file separate from your compiled project and load it in as a mod then this isn't how you do it. You have to 'compile' the scene as a PCK (same way as you compile the whole project) and load it in that way.

res:// references the 'location' inside of a PCK file and not the actual file system that your game is launched from. Kind of, best way I can think of describing it.

please read all the post. Even trying using a line lik e this

load("res://your_path/scene_name.tscn")

causes me an error. I cant instancing, it causes me an error

@TwistedTwigleg said:

@"K-Storm-Studio Ltd" said: Just forget the PCK file for now man.

Alright...?

I've just created a simple Node2D scene with a sprite, nothing else. Saved as tscn file And I cant add it to the main project at runtime, cant understand

Where is the tscn file saved? How are you adding it to the project at runtime?

var next_scene = load("res://mods/Crab.tscn")
# Attach the loaded scene to the current main node
add_child(next_scene)

@"K-Storm-Studio Ltd" said:

@TwistedTwigleg said:

@"K-Storm-Studio Ltd" said: Just forget the PCK file for now man.

Alright...?

I've just created a simple Node2D scene with a sprite, nothing else. Saved as tscn file And I cant add it to the main project at runtime, cant understand

Where is the tscn file saved? How are you adding it to the project at runtime?

var next_scene = load("res://mods/Crab.tscn")
# Attach the loaded scene to the current main node
add_child(next_scene)

Is there a scene called Crab.tscn at res://mods/Crab.tscn in the Godot file browser in either the project that is loading the .pck file or the project which are you exporting the .pck file from? You can check in code using something like this (untested, based on this answer from Q&A):

var file_checker = File.new()
var file_checker_exists = file_checker.file_exists("res://mods/Crab.tscn")
if (file_check_exists):
	print ("File exists and should load")
else:
	print ("File does not exist and therefore cannot be loaded")

' Also, is the Godot debugger giving you any errors outside of a null instance?

@TwistedTwigleg said:

@"K-Storm-Studio Ltd" said:

@TwistedTwigleg said:

@"K-Storm-Studio Ltd" said: Just forget the PCK file for now man.

Alright...?

I've just created a simple Node2D scene with a sprite, nothing else. Saved as tscn file And I cant add it to the main project at runtime, cant understand

Where is the tscn file saved? How are you adding it to the project at runtime?

var next_scene = load("res://mods/Crab.tscn")
# Attach the loaded scene to the current main node
add_child(next_scene)

Is there a scene called Crab.tscn at res://mods/Crab.tscn in the Godot file browser in either the project that is loading the .pck file or the project which are you exporting the .pck file from? You can check in code using something like this (untested, based on this answer from Q&A):

var file_checker = File.new()
var file_checker_exists = file_checker.file_exists("res://mods/Crab.tscn")
if (file_check_exists):
	print ("File exists and should load")
else:
	print ("File does not exist and therefore cannot be loaded")

' Also, is the Godot debugger giving you any errors outside of a null instance?

File does exist, even using my passed variable 'modname'!

instead in the add_child command , the debugger gives me this error: W 0:00:00.661 The argument 'index' is never used in the function 'on_ItemList_item_selected'. If this is intended, prefix it with an underscore: 'index' <C++ Error> UNUSED_ARGUMENT <Source> SystemLoad.gd:48

Im figuring out the problem but I cant get the solution.

So now it does work using a .TSCN file scene but not a PCK file. And I need a PCk as a distributable file . Any advice please? (woooow0)...

	var next_scene = load("res://mods/" + str(modName))
	var instacedScene = next_scene.instance()
	# Attach the loaded scene to the current main node
	add_child(instacedScene)

ok!! the code below works. However the problem about the script above is the we have to get the name of the resources into the PCK file.

	ProjectSettings.load_resource_pack("res://mods/" + modName)
	var next_scene = load("res://Starfish Friends.tscn")
	var instacedScene = next_scene.instance()
	# Attach the loaded scene to the current main node
	add_child(instacedScene)

So now, is there a way to read the filenames within ?

ok the only thing that I need to do is loading content using variable, Im opening a post, thanks man

2 years later