How to run specific collection?

Problem: run selected/specified collection as bootstrap without interfering to main.collection.

Found a bunch of topics, most recent was 2 years ago.

My current approach is using bob:

  1. make build to apply changes.
bob --variant=debug
  1. make binary executable
chmod +x build/x86_64-linux/dmengine
  1. finally tell dmengine to override bootstap and run!
build/x86_64-linux/dmengine --config=bootstrap.main_collection=/collections/tests.collectionc

But here is 2 problems:

  1. dmengine can’t run collection that doesn’t exists, so you must inlcude tests.collection into main.collection (for example as collection proxy)
  2. you have to run 3 commands each time when you change something (which can be automated) and wait around 2 seconds each time (hello unity!)

Maybe someone have different approach?

  1. To include tests.collection (or anything else) in the bundle without referencing it somewhere, you can declare it as a custom resource in game.project, in the “Project” category.
  2. Are you bundling the game every time you make a change to it, maybe because you want to test it without Defold’s profiler and all? Or do you want to test different collections without changing the value in the game.project file because you might forget to change it back?

My approach is to have two collection proxies in main.collection and use a script to determine which collection is played. It would look like this. It follows the “loader” pattern described in the Collection Proxy manual.

go.property('play_debug_collection', false)

function init(self)
	if sys.get_engine_info().is_debug and self.play_debug_collection then
		msg.post('#tests', 'load')
	else
		msg.post('#start game', 'load')
	end
end

function on_message(self, message_id, message, sender)
	if message_id == hash('proxy_loaded') then
		msg.post(sender, 'init')
		msg.post(sender, 'enable')
	end
end

Then the file path and toggle belong to main.collection instead of in game.project, and the debug collection won’t be accidentally loaded in a release build.

Building on the proxy idea, one trick that keeps main.collection untouched is to add a custom key to game.project, something like [bootstrap] start = level_03, and read it at startup with sys.get_config_string(“bootstrap.start”). Your loader script then picks which collection proxy to load from that value. When you bundle from the command line, bob can override the value with a small .ini passed to --settings, so you can make test builds that start on a given level without editing the project. It also means nobody accidentally commits a changed main collection.

1 Like

If you use a custom key like that, then you could play different levels in the editor by entering the command line argument in the editor preferences window (File → Preferences), making it truly local to your editor. :ok_hand:

It’s not quite as slick as testing a random scene in Godot, but I like it.