Jump to content

[SOLVED]Adding object by code when save level get two versions


photo

Recommended Posts

Hi

 

If I add objects by code (ObjectGUI_2) then run the game in editor and press save, I get two version of the ObjectGUI_2 and ObjectGUI_3 :(  

 

 

How to stop this?

 

 

ObjectGui object_gui = add_editor(new ObjectGui(45.0f,35.0f));

 

 

Link to comment

Hi Paul.

 

You have two ObjectGui nodes in a save state. The first ObjectGui node is a node in a world script. The world script knows about this node because you created it by "new" operator. Second node is node in editor script. The editor script knows about this node after "add_editor" function calling. If you need this node in editor just call "node_remove" function like this:

ObjectGui object_gui = add_editor(node_remove(new ObjectGui(45.0f,35.0f)));

See also: https://developer.unigine.com/en/docs/1.0/code/memory_management#editor

Link to comment

Hi yingaz 

 

Once I add this code " ObjectGui object_gui = add_editor(node_remove(new ObjectGui(45.0f,35.0f))); " I get the following error see image:

 

 

post-1284-0-45187000-1396261311_thumb.png

 

 

Thanks

Paul

 

 

 
 
 
Link to comment

Its running in a script (videoObject.cpp) that is called from the world script 

 

ObjectGui object_gui = add_editor(new ObjectGui(45.0f,35.0f));

object_gui.setPosition(Vec3(-39.6f,-20.0f,-12.0f));
 
object_gui.setMaterial("gui_base","*");
object_gui.setProperty("surface_base","*");
object_gui.setMaterialState("mode",2,0);
object_gui.setBillboard(1);
 
Gui gui = object_gui.getGui();
sprite_video = new WidgetSpriteVideo(gui,"data/all_unigine_newgame/videos/SQ001_SH0010_Fill_Up_01_High.ogv");
gui.addChild(sprite_video,GUI_ALIGN_EXPAND);
 
 
How to change the above code so I don't use the add_editor ?
 
 
 
 
 
Link to comment

Still not working for me 

 

I have this code now:

 

ObjectGui object_gui = new ObjectGui(45.0f,35.0f);
engine.editor.addNode(node_remove(object_gui));

 

But when I press "SAVE" in the editor

 

post-1284-0-07978600-1396428264_thumb.png

 

I get two versions of the object!

 

All I want to do is add some objects by code and some objects by the editor or both and save the scene.

 

 

 

 

Link to comment

Hello paul.w,

I'm afraid, that all the objects added to the editor will be saved into the .world file. So after world reloading engine creates all nodes from .world file and all the nodes defined in script.
You can check it by saving SDK samples from the editor.

To avoid this issue, you can check the nodes from script(by name, for example) and skip the nodes which already exist.

The other way is to edit all objects from editor or from the script only.

Link to comment

Hi,

Could you describe what do you mean by "main.cpp"?

Also, if you want to create something using scheduler, remember that it starts after init.

Link to comment

Hi Paul, the "project_name.cpp" is a main cpp world script file for the default "project_name.world" which automatically generated by "New project" browser function. This is a just sample world. If you are use a Game framework please see a level creation from Game framework editor https://developer.unigine.com/en/docs/1.0/scripting/scripts/game_framework/editor#level_creation.

In the Game framework logic your custom world logic must be implemented in Level based class (see https://developer.unigine.com/en/docs/1.0/scripting/scripts/game_framework/editor#custom_level_logic).

But you can't work with a editor while the game is running. It may cause the engine crush.
Another way (Game framework hack) to work with a editor is a modify "framework/game/game_world_script.h" file and write your custom logic while editor is running (you can check editor running by engine.editor.isLoaded() function). This file is main world scrip logic for all Game framework levels. But be careful when changing logic and make sure that you can merged this file with new file version when it will be updated in a follow SDK.
I hope my answer can help you
Link to comment
×
×
  • Create New...