Hi, I have a question about create object when loading new world, and I'm not sure that I'm doing this the right way.
This is sort of my current code.
Code:
// D.viewRange() is 100
Game.World.activeRange(D.viewRange()).mode(Game::WORLD_FULL)
//.setObjType(all objects type)
.New(UID(WORLD));
if(Game.World.settings().environment)Game.World.settings().environment->set();
if (ObjectPtr tmp=Objects.ptrRequire(UID(NON_CONST_OBJ)))
{
Object obj; obj.base(tmp);
// setting some params
obj.sortParams()
Vec pos=Game::World.findWaypoint(UID(WORLD))->points[0].pos; // ~Vec(17, 0.6, 19)
pos.y=Game.World.hmHeight(pos.xz(), false);
Matrix mat; mat.setPosScale(pos, obj.scale())
mat.rotateYL(RandomF(PI2)); // random facing angle
Game::World.objCreate(obj, mat);
}
BackgroundLoader.start();
Is this the right way and time to create object on new world, or should I let the world finish loading before create an object? And how do I know that it is loaded and safe for dynamic object?
Because, sometimes pos.y is 0, which is probably fail to get Game.World.hmHeight (according to desc), and make that object failed to appear. (Logged position is Vec(17, 0, 19) but ObjMap.elms is 0, yet Game::World.objCreate() return 'true')
Edit: Mostly happens to Object that use obj.base(BASE_OBJ) though.