Stream in Godot Resources, Scenes, Scripts, etc. for on-the-fly Updates in GD Script

Godot Version

v4.4.1.stable

Question

New to Godot, but not new to the game industry. :wink: I am still in the early learning process of this game engine. I sometimes use Ai to ask theoretical questions to get a general idea of capabilities and not code examples (because it sucks at them :laughing:) I am hoping that those pros here with much more experience with Godot than me can answer these general questions about what is and is not possible with GD script.

Using the Godot tutorials have been very helpful at quickly learning how Godot is structured and what GD Script can do (which is great so far!), so I’m quickly working my way into more advanced ideas about what I can do with the Godot engine. I’ve done enough testing with the HTTPRequest Node that I understand what I can bring in or send out from the game engine, which is another bonus. So now, I’m moving to subjects such as streaming components of a game into Godot.

Questions:

  1. GD Script, appears to me, that I can re-create the entire structure of my game completely in script; such as creating scenes, nodes, sprites, etc. Does this apply to scripts? Such as, using GD Script to create a scene, then using a HTTPRequest Node to download a script that should be attached to that scene?
  2. Can GD Script create other GD Scripts and then save in the code from somewhere else (either in the GD Script already or downloaded externally)?
  3. If GD Script can create or download external GD Scripts for attachment, how does the game engine handle the run-time of such scripts? Do they function the moment they exist, do they need to be “loaded” in some way to start their own execution, etc.?

GDscript can create nodes and other GDscript or any files but it’s not a efficient way to make a thing like an add-on,level or what you want and whole game is absolutely not.
It would be great if you explain what you really want : )

Basically, I want to be able to create a collection of games but not have to put it all into one “mega-game”. You mentioned it would not be efficient, but is that in terms of loading time or would it affect the actual speed that the game runs at?

I’m not trying to run the entire game in a complete streaming mode, more like, I want to be able to stream smaller games into one game. That way, the main game is the starting point and each smaller game can load in dynamically. This way, if any changes made to the smaller games (updates, bug-fix, etc.), I don’t have to release the “main” game every time for an update.

So to clarify, I want to avoid having to create Game1, Game2, Game3, Game4 as all separate games that would have to be all downloaded, installed, started separately. I want to create Game_Main and it loads in the proper resources for Game1, Game2, Game3, Game4, etc.

This way, Game_Main can be “small” in size and then load in (download) the other Games as played by the player. Game_Main would also be able to load in the latest version of Game1, Game2, etc. externally without having to compile out those games separately for every update or bug-fix made to them.

Yeah then it’s possible and the automatic update is a cool thing you can absolutely try!

And you can ask for any help in forum like any!

You can create new GDScript scripts using the class GDScript

Example:

extends Node

var payload = """
extends Node

func _ready() -> void:
	print("Hello world")
"""

func _ready() -> void:
    # Create a new GDScript resource and set its source code
	var script = GDScript.new()
	script.source_code = payload
	# Reload it so the source code gets parsed
	script.reload()
	
	# Create a new node
	var node = Node.new()
	# and set its script to the newly created script
	node.set_script(script)
	
	add_child(node)

But it’s better and a more robust way if you can pack whatever you need into pck files and download those instead. Here’s some info about that:

You can also create those pck files with code using PCKPacker

This example is perfect! :grin:
I was able to experiment with calling the code from a web server and eventually out of a pck file that was downloaded from the same web server. This fills in a big gap in my Godot learning experience. It also answered all of my “what if” questions because I could experiment to see what is the correct way to use this and what is not the correct way, etc. :+1:

I appreciate you taking the time to create this code sample and I hope this helps others in the future that may ask the same question. :grinning_face: