UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.41k stars 179 forks source link

Converted blender object doesn't keep its parent/children relations #1716

Closed ThiagoMoraesGD closed 1 year ago

ThiagoMoraesGD commented 2 years ago

As stated in this thread: https://blenderartists.org/t/upbge-0-3-append-external-blend/1389754

Trying to append a rigged model from another file in game, using bpy.ops.wm.append and convertBlenderObjectsList() but after import the object to the actual scene, i lost all objects relations (parent/children) blend.zip .

youle31 commented 1 year ago

Hello, I did a test branch here:

https://github.com/UPBGE/upbge/commit/fc116a8462035347a9ccd164743e1eb965d36d0a named insta_col_runtime_test.

I only tested 1 case (test file at bottom -> it is to add objects with a rigid body constraint)

If you want you can test for your cases (children and track to) USING instance collections to see if it works properly. As it's complex for me, i have difficulties to know what kindof bugs it could generate.

youle31 commented 1 year ago

I'll link test files here and edit when i test something:

https://github.com/UPBGE/upbge/files/10789612/insta_col_runtime_test.zip

parent_child.zip

track_to.zip

And I share a test build:

https://ufile.io/1ijd73mf

(it is the build of the branch to test to convert instance collections during runtime). (the ufile.io link expires in 1 month or something like that)

youle31 commented 1 year ago

Fixed here: https://github.com/UPBGE/upbge/commit/40fffb47d90d3c595919eaa61102ec04d55203eb

It sometimes needs some tweaks with python to have it working properly

ThiagoMoraesGD commented 1 year ago

Hi, i test the new master but it seems that is not possible to iterate trough all objects..Do i have to convert one by one?

youle31 commented 1 year ago

you have to convert instance collection 1 by one but instance collection contains as many objects as you want.

The instance collection can be either converted to active list (scene.objects) or inactive list (scene.objectsInactive). The instance collection itself in bge is just a gameobject but not visibled and with no physics. Only instances created from instance collection are complete gameobjects with physics, logic...

maybe print scene.objects and scene.objectsInactive to see what is is active list and in inactive list, you will see what has been added inside.

youle31 commented 1 year ago

also, you can have a look at https://upbge.org/docs/latest/api/bge.types.KX_GameObject.html#bge.types.KX_GameObject.groupMembers https://upbge.org/docs/latest/api/bge.types.KX_GameObject.html#bge.types.KX_GameObject.groupObject

it's same than in bge 2.7