Store a runtime edited / converted gameObject to disk, recall from disk.

I have been working on a system to edit terrain, and place gameobject instances in game, and then I was going to use BP-Player to store these meshes inside .block files, to load later,

I can’t find an API or command that sounds like it could help me do this and C-106 delta is MIA.

the idea is this ->

what better way to make a city in a game then to play sim city (without the gamification)?

what better way to make a building then to assemble it in game from modules like fallout 4 settlment editor kinda?

This all works and I can add more tools to it after I have a method to store and retrieve the gameobjects from file, and load them in when needed, and then save the meshes back to disk and unload them when not needed.

if BP_Player is taken off as an option (temporarily or permanently) I could use another method to save gameobjects to disk and retrieve them and their physics meshes, vertex data etc.

I understand I could load patches in blank, libNew the GFX mesh and then set vertex normals and color and height, and then resistance physics meshes , but all that sounds much heavier than being able to load pre-converted game data.

… Libload …
It isn’t preconverted, but with async and clever caching you can make it hife any load times.

But I need to write .blends then from inside bge, and create blender mesh data etc to match what I craft in engine, and do that potentially every frame (unloading data and preserve changes)

I don’t think you can save bge objects…

But there are ways to use bpy:
You can run a separate blender instance to create and save bpy meshes over sockets.
Running the create mesh script from as a command line argument for blender might also work.
I have heard about using blender as a python module…

The idea is from:

You can write any file format you like as long as you know the format.

Is that worth? I’m sure it is not.

You modified the mesh in game. You can store these changes and reapply it later .

The thing is I will be loading and unloading tiles constantly, there will be the terrain, but also buildings, roads, trees etc, I was using the tiles as a form of hiarchy for loading…

I suppose I could have the tiles load in their terrain patches, and their building/trees etc over time once they spawn in…

The player will be driving occasionally /potentially flying fast.

I think saving whole groups of objects and loading whole groups of objects just sounds faster than using addObject and EndObject…

I was thinking that saving /loading files should be a no brainer
We need this in the api.

LibSave?

Or maybe

scene.save([groupOfObjects] , “path/fileName”)

If I could pay someone to write this patch, how much would it cost?

Bge Needs streaming, and if libLoad asynchronous the has been fixed, the only logical next step is asynchronous unloading to file.

I can shoehorn using a separate bpy server and socket, but we need this to be easy and fast.

Modern engines stream data.

please upvote*

Hey, I’m experimenting right now with sending blend data to a remote location and libloading it on a client (to produce game patches like game updates or paid extra content). I’ll tell you how it goes, but I don’t think it will involve BGE edited objects, just things normally modified in blender.

EDIT:
Well, it worked, but I don’t think it will do quite what you need. I’m not sure how you would save the data generated within BGE to a blender format. The mesh proxy object you find in BGE is not the same as the Mesh object that exists in BPY. Blender scenes are first converted to something a little different when starting the game engine. I wouldn’t know how to go about converting them back.

You might be able to think of a use for this though.

We need to run the converters backwards, and generate a blender object from a bge object,

Basically the code exists in reverse already in BGE.

Are you sure? Where do you think the BGE creates BPY data?

ok worked around!

I made a dictionary I store the data I need in, and then used KDTree to tell what data I needed
(macro (objects))

and I regenerate the micro tree (vertex) from the loaded in objects if it has not been done,
else I regenerate it from a list stored in the object (pre-proccessing)

almost stable 60 fps while streaming meshes and editing meshes in a huge terrain

Yeah, I think a save/load dictionary would work the best.

Be wary of memory leaks. If you’re storing generated data and never deleting it, then the program will gradually use more and more memory - one example is to always be appending to a list, but never removing. You may want to read up on how to build a nice caching system. Something like python’s built in LRU cache can result in huge performance gains for operations like this. One example use:


import time
import functools

@functools.lru_cache(maxsize=512)
def generate_terrain_tile_data(tile_x, tile_y):
    time.sleep(0.5)
    return tlle_x + tile_y

print(generate_terrain_tile_data(1,2)) # Takes 0.5 seconds to run as there is the time.sleep
print(generate_terrain_tile_data(1,2)) # Takes very little time to run as the result is already cached
print(generate_terrain_tile_data(2,2)) # Takes 0.5 seconds to run as this has not been calculated yet
print(generate_terrain_tile_data(2,2)) # Fast
print(generate_terrain_tile_data(1,2)) # Still fast

Also run some tests to make sure that it’s actually running faster than just toggling the visibility of the terrain tiles. If you want to spread the processing over more frames you could have some tiles that are invisible, and calculate the position/normals for them over several frames before making them visible.

I will be using each tile to load in / load out gameObjects as a basis for a hiarchy to spawn over a few frames

I don’t want to bloat scene.objects, and my buildings are made of modular building kit instances using an atlas (thousands of objects potentially)

Invisible terrain tiles would be just fine, however i still need to remove / store anything the player potentially changes

(this is attempted to work for almost any game without the user knowing heavy python)

Create or edit “tile.blend” (splat map basis nodes)

Create or edit a /library/manifest of game object instance to be able to place,

Fire up editor make initial map or final, save / load edit later

Open with “game” instead of editor as a second .blend