Jump to content

Console command not available in editor


photo

Recommended Posts

Hello,
In AppWorldLogic::Init method I'm adding my command using Unigine::Console::get( )->addCommand (I've tried do the same but in AppEditorLogic::Init - same behaviour)
If I run application through launch_debug.bat or launch_release.bat - command is available, I can use it, but if I run my app through launch_editor.bat and in editor console I'm trying to invoke my command I only get "Unknown command" error.

How can I add command that will be available in editor console?

PS. I'm creating complicated nodes hierarchy in runtime and I want to see If it's correct in "easy way" in editor "world node hierarchy" window.

Edited by arzezniczak
Link to comment

Hi.

You're using C++ or C# I guess? If so, Editor wouldn't "see" any written logic.

There are two workarounds:

1. Use UnigineScript. Add your console command in the project_name.usc file. This will work in the Editor. For instance:

void console_action_callback() {
	log.message("first action! no arguments!\n");
}

// a script function to be executed for 1 argument input
void console_action_callback(string arg) {
	log.message("second action! the argument is: %s\n",arg);
}

int init() {
// add a command
	engine.console.addCommand("console_action","my_command description","console_action_callback");
  	
  	return 1;
}

2. Save the node with saveNode and check it manually in the Editor: https://developer.unigine.com/en/docs/2.8/api/library/engine/class.world?rlang=cpp#saveNode_cstr_Node_int_int

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment

Yes, I'm using C++ API.

First I've tried second workaround - generally it works but it's a bit pain to iterate with this save/load method.

Then I've tried the first one and I have a problem. I'm using some external dll during this node creation process. I have tried to pack everything into one function in namespace and export to script using Interpreter::addExternFunction, but Editor is complaining that name of my namespace is "unknown token". Any idea what I'm doing wrong here?

C++ side:

// main
#ifdef _WIN32
int wmain(int argc, wchar_t *argv[])
#else
int main(int argc, char *argv[])
#endif
{
	Unigine::Interpreter::addExternLibrary( "ImportHelpers" );
	Unigine::Interpreter::addExternFunction( "ImportHelpers.Import", Unigine::MakeExternFunction( &ImportHelpers::Import ) );

	// init engine
	Unigine::EnginePtr engine(UNIGINE_VERSION, argc, argv);

	// UnigineLogic
	AppSystemLogic system_logic;
	AppWorldLogic world_logic;
	AppEditorLogic editor_logic;

	// enter main loop
	engine->main(&system_logic, &world_logic, &editor_logic);

	return 0;
}



// ImportHelpers.h
namespace ImportHelpers
{
	void Import( Unigine::String filePath );
}



// ImportHelpers.cpp
void ImportHelpers::Import( Unigine::String filePath )
{
	//importing file using external lib, creating Unigine nodes etc...
}

 

Unigine script:

void my_import_callback(string arg) {
	ImportHelpers.Import(arg); // here interpreter complains about 'unknown token "ImportHelpers"'
}

int init() {
	// Write here code to be called on world initialization: initialize resources for your world scene during the world start.
	
	Player player = new PlayerSpectator();
	player.setPosition(Vec3(0.0f,3.401f,1.5f));
	player.setDirection(Vec3(0.0f,-1.0f,-0.4f));
	engine.game.setPlayer(player);
	
	engine.console.addCommand("my_import","my_import desc","my_import_callback");
	
	return 1;
}

 

Link to comment
×
×
  • Create New...