How to use LibLoad, LibNew, LibFree, etc, for load objects and more?

Hi, i can not understand much the documentation about this, someone can explain me, how use the LibLoad, LibNew, LibFree, etc?

Questions…

1)How load directly a object from another file?
2)How load a scene, and in other moment load a specific file of this scene.
3)How delete later the objects added.

I will use this for load objects of another files, sorry english :smiley:

I’ll do the basics first:


The simplest way to use Libload is to load a scene from a blend file. It will load the currently active scene, and any objects in the active layer will be added when it finishes loading.

path = bge.logic.expandpath('\\blend.blend')
bge.logic.LibLoad(path, 'Scene')

Voilla, your scene will load.

To get rid of it, you use LibFree:

bge.logic.LibFree(path)

And that’s pretty much all I ever do with LibLoad. These days I’ve been playing a bit with Async, but find that it can be a bit of a hassle. To use Async, you do something like this.
Initiate Load:

path = bge.logic.expandpath('\\blend.blend')
handle = bge.logic.LibLoad(path, 'Scene')

To find out how much it’s done (ie every frame to update a loading bar etc):

print(handle.progress)

You can also add a callback so that when it’s finished a function is run. This is probably meant for removing the loading bar:

def end_loading(status):
    print('I am finished loading the file')
    
handle.onFinish = end_loading

I’m not quite sure what status is, but I’ve never had to use it. Probably a simple True False thing?


So, about your specific questions:

1)How load directly a object from another file?

Have it in an active layer and use libload with type ‘Scene’ is one way. Otherwise you can use type ‘Mesh.’ I have not tried this method so I can’t tell you exactly how to use it. Perhaps someone who knows could tell me? I’m keen to learn.

2)How load a scene, and in other moment load a specific file of this scene.

See the stuff above for how to load it. But I think what you are asking here is how to load a scene, but not show anything and then later add objects from it?
In this case, yeah, go ahead and load it using type ‘Scene’ but make sure you saved it with all objects on inactive layers. Then from in the game, you can simply search the inactive objects, and add it from there.
(It’s bge.logic.getCurrentScene().objects_inactive I think)

3)How delete later the objects added.
The same way you remove other objects: grab them from your script and use end_object (or logic brick equivalent), or libFree the library, the game engine will remove them for you, but they will no longer be able to be added. (and anything else from the blend will vanish)

1 Like

Correct me if I’m wrong, but isn’t LibLoad just adding the scene so it can be picked up by bge.logic.getSceneList()? Current scene is the scene you still have playing and where you libloaded from. So you’d first need to find the scene you added (is there something in LibLoad that actually returns it or do you have to search the list returned by getSceneList?) and then look for scene.objectsInactive[“name”] or do a search on the list.

No. The ‘Scene’ type is actually somewhat misleading. When you LibLoad a blend file using ‘Scene’ type, all of objects in all of the scenes in that blend file are added to the current game scene. LibLoad doesn’t load a specific scene, and no new scenes are added to the current game.

Note that the added objects keep their active/inactive state upon being loaded, so it usually a good idea to keep your objects on inactive layers in blend files you’re loading from. This way you can add multiple copies of them and have more control over when active versions of them are added to the current scene.

1 Like

No. The ‘Scene’ type is actually somewhat misleading. When you LibLoad a blend file using ‘Scene’ type, all of objects in all of the scenes in that blend file are added to the current game scene. LibLoad doesn’t load a specific scene, and no new scenes are added to the current game.

Ok, good.

So based on that what would be the proper way to switch to a scene in different .blend file? For level change purposes, for example? Do you have to go around it and actually “change the scene” by switching out the objects in the current scene (using libfree) and loading in the new content with libload?

Try the ‘start game from file’ actuator (logic bricks) or the equivalent bge.logic.startGame

Or, what I’ve done in my Generic Game Template is to use libload on a scene with only a single empty in it. To progress onto the next scene I restart the blend (using bge.logic.restartGame) and have an external way of keeping track of where I am currently (a txt file).
I would recommend restarting restarting the scene/game/file for each level or at least changing the scene/game/file just to make sure sections from the past file aren’t influencing the current file.

So that doesn’t even carry over the globalDict?

Or, what I’ve done in my Generic Game Template is to use libload on a scene with only a single empty in it. To progress onto the next scene I restart the blend (using bge.logic.restartGame) and have an external way of keeping track of where I am currently (a txt file).

I was wondering what would be a good way to read/write some of the types such as lists and matrices in text file? I know gameobjects won’t work and shouldn’t be stored in the first place.

I would recommend restarting restarting the scene/game/file for each level or at least changing the scene/game/file just to make sure sections from the past file aren’t influencing the current file.

But most of the time when we talk about complex games with inventories, AI characters, revisiting other levels, etc, you will want certain information to carry over, is there really no better way than to wipe everything clean and carry the information in a text file?

Yes it does.

Ok, I was just wondering why would sdfgeoff use text file if it does. There are some, like you could use text file for your save system, I guess.

I hope you know how much this saves time as I don’t have to trial and error this stuff :slight_smile:

Ok, thanks for the help @sdfgeoff and everbody.

:Din this moment I’m a little busy for test, so i have another questions:

1)I use the kupoman lod, so for example i have a line of trees in a blend, i use libload for load the trees, and the models of the lod is in a inactive layer, how import the lod objects in a inactive layer?

without this the lod not work! Sorry english :smiley:

By having them in an inactive layer in the blend file you are libloading.

And are you sure globalDict is preserved when you start another blend? I’m pretty sure it isn’t, or at least it wasn’t when I was developing DEEP Space a couple years ago. I’ll check later I guess.

Ok, thanks for you help, i test everthing and work perfect :smiley:

I use it a lot in my game. So yes it’s preserved.

Bottes d’hiver pour les filles peuvent tre fabriqus de nombre de matriel et l’aide de beaucoup de conceptions diffrentes. Il ya une varit de modles sur la liste des chaussons d’hiver que tout coup entrer la mode chaque anne. Il peut y avoir cependant plusieurs conceptions classiques sur la liste des bottes d’hiver pour les dames,jordan 13 pas cher, qui sont habituellement la mode pour presque tous les ans. Heather HemmensHeather Hemmens,air jordan femme, better known for her role as Alice Verdura on CW’s cheerleading comedydrama “Hellcats”,new balance chaussures, is sassy and she knows it. The Costa Rican actress (raised in Maine) is one proud Latina. “When someone says ‘Tell me about yourself,new balance homme,’ I wish I could answer simply,nike air max requin, ‘I’m Latina!’” she told Latina Magazine. Cat Pose (Marjaryasana)The beginnerfriendly cat pose is a great way to relieve tension in the spine,jeremy scott wings femme, shoulders and neck,nike air max 2013 pas cher, and to boost circulation in the upper body. Begin with your hands and knees on the floor in a tabletop position, and gently round the spine up as you exhale. On the inhale, return to a neutral spine… That idea seems to get a little lost with Millenials. Often what replaces it or at least takes a front seat, is the entitlement to be all in even in areas where clearly they have no experience or no explicit decision making responsibility. Some will balk at the realities and very unglamorous necessities,nike blazer femme pas cher, preferring to skip over them. I was very shocked when i came back and notice that my wife is engaged to someone else. I gave him a trial and to my greatest surprise,jeremy scott wings, it worked. Stephine is back home with my son and i am the most happy man on earth. In addition, childless couples and individuals caring for a disabled family member often get a similar range of stupid questions hurled at them by total strangers. Rather than a list that is by no means comprehensive,new balance 420 femme, my advice to those who feel compelled to comment to strangers about their life situation is, "don’t make assumptions . Before you make a comment or ask a question,nike blazer, think about how YOU might feel if that question was asked of you . Either be part of the solution or move along so someone else can get the job done. OH,jeremy scott pas cher, and remember those are kids at Hollywood High. They deserve your respect not disdain. The placement of the USB and Aux ports, lower left corner, is poor as a result of a USB stick poking out of the port can simply be hit by my hand when moving the shifter on the steering column. These can be higher off on the lower right as a substitute of decrease left corner. Depending on the setup in your automotive that may not be an issue for you… ???: recreations he is correct From a strategic standpoint you can scrape that layer off you really should find above mentioned tips helpful…