I’ve been working on a new game project and have gotten to the point where I am separating my assets from the main file and loading them when entering each level using LibLoad. The problem is that it is taking an extremely long time to do this (around four minutes).
My main blend file contains two characters, each consisting of an outer ‘physics cage’ cube and an inner ‘sprite’ plane. The inner plane is swapped out depending on the direction they are facing (using replaceMesh) for another plane (selected from a hidden layer) with different uv coordinates on the main spritemap, which gives the illusion of movement. This part has been working fine with no issues once the scene eventually loads.
The sprite frames for each character are stored in separate blend files, each containing 1024 planes (around 4000 verts for each character). The strange thing is that it takes libLoad around 4 mins to load in these 8000 verts when the game starts, and I have no idea if this is normal - I would have thought that it would have been instantaneous for files of this size.
So, is this unusual? Is LibLoad broken, or am I doing something horribly, horribly wrong?
I’m using:
UPBGE 0.2.3
Linux Mint 18.3
Intel NUC i7, 16 GB RAM
This is the code I am using to import the assets:
import bge
from bge import types, logic
class Level:
def __init__(self, sys):
self.system = system
self.player_libs = {}
self.enemy_libs = {}
self.create_map()
def load_and_merge(self, asset, type):
path = "//resources/" + type + "/" + asset + ".blend"
libraryStatus = bge.logic.LibLoad(path,"Scene")
return libraryStatus.libraryName
def create_map(self):
self.place_player()
self.place_enemies()
def place_player(self):
self.player_libs[identity] = self.load_and_merge("player", "agents")
def place_enemies(self):
scene = logic.getCurrentScene()
spawn_points = [ob for ob in scene.objects if "enemy" in ob]
for p in spawn_points:
if p['enemy'] not in self.enemy_libs:
self.enemy_libs[p['enemy']] = self.load_and_merge(p['enemy'], "mobs")
spawn_obj = scene.objectsInactive[p['enemy'].capitalize()]
new_enemy = scene.addObject(spawn_obj, p)
Hi WKnight02, thanks for the reply. I had that problem a few days ago, and so I added the enemy_libs dictionary and a conditional to check whether the library / enemy type had already been added. I’m not getting the error anymore, so I don’t think the slowdown is because of that. But who knows, I could be overlooking something.
Hi BluePrintRandom. I’m triggering the functions above using an Always sensor on tap mode with a check for a positive pulse as you suggest, but still getting the same result. I’m also printing out test values in each of the functions, and they output to the console once each. Hmm.
Ok, I’ve just done a couple of tests: firstly, I tried replacing the two asset files that are being loaded in with empty .blend files, and it loads instantly in the main file through LibLoad (as you’d expect). Then, I added a cube to each file and subdivided them until they were both about 10,000 verts - no problem, it loaded instantly. Finally, I deleted all of that and added 6,000 planes, and it loaded in less than a second. So, it looks like the problem is with the original asset files.
I’m not sure what would be causing the issue within these files, since the spritemap used in each is about 200kb, and the only other things of interest in the files are the sprite frames.
I’ve attached the file below in case anyone can spot the problem. Thanks!
(also: these are only placeholder spritemaps and not an artistic statement :))
The issue is that you have one thousand materials. When libloading, each of those materials has to be compiled by the GPU, and in the case of the Intel NUC, the GPU isn’t very good. (Shader compilation is the major loading time on all the projects I’ve ever done targeting integrated hardware)
I couldn’t figure out why you had so many materials (what is the difference between them?) but I suspect you should investigate UV mapping? Or just get them all to share a material.
Yes sdfgeoff, you’re completely right. I’m picking up Blender after a while and assumed that objects couldn’t share the same material while also having different uv coords.
I’m relieved to find out that it was my own stupidity rather than a bug or something. I should have more faith in the devs…