Added Objects Persists in Blender

To put it in simple terms, I’m making a level editor with the game engine. However, I need changes made in the game engine to persist in Blender (e.g. If I add a cube to the scene in the game engine, it should be there in Blender after the game engine ends).

Is there any easy way to do this? The only thing I came up with was to keep track of all the objects added in the game engine, save the list, and then run a bpy script that re-adds all the objects outside of the game engine.

My first thought:

Why not use Blender as level editor?

You can run access the bpy API from within the BGE as long as it is running in Blender. But all changes are applied AFTER the BGE ends.
I think storing data into a “level” file would be the best solution as this is what a user would expect from an editor.

Either way you need a converter to convert from BGE data to Blender data.

Like I said, “level editor” was putting it in simple terms. What I’m really doing is adding objects based on data coming from external sensors via serial cable.

Since I’m not directy controlling what’s added in the game engine, I want to be able to edit what’s been added after I exit the game engine.

I guess I’ll see if using bpy in game engine will work.

Wouldn’t it make sense to write a Blender script and run it directly in Blender?

Maybe you can write an Addon for your needs?

Got it working (I think). I just made a method that takes a game object as its argument. It then uses bpy to add the object outside of the game engine. I simply call this method every time an object is added in the game.

I haven’t done very thorough testing, but it seems to work fine so far. I’d be happy to share the code if anyone else is interested.