Upbge 0.3 addOverlayCollection python

Hey guys,

I wanted to convert a script to 0.3. We can’t use overlays anymore so we need to use collection. That is fine, however i don’t get it to work.

I call it with python

def test(cont):
    
    own = cont.owner
    
    own.scene.addOverlayCollection('hud_camera','Hud')

I get the following error

Failed to convert collection.
Error: Python(Cube), Python script error
Traceback (most recent call last):
  File "C:\Users\germe\Desktop\test.blend\script.py", line 5, in test
SystemError: <method 'addOverlayCollection' of 'KX_Scene' objects> returned NULL without setting an error

So i thought maybe i need to uncheck the checkbox from the hud collection… Instant crash, blender just closes itself. Then i thought well maybe it needs to be invisible, so i click the eye icon, same error occurs.

Am i doing something wrong here?

A test.blend
test.blend (851.8 KB)

Note: with bricks it works, but that’s not an option for me.

what about constructing a object with python and putting bricks in it and converting it?

own.scene.convertBlenderObject()

this is good for source control and gives py EVERY power bricks have

as for the method I will ask youle about it.

Why make a way around it, while there is an option build-in for it?
If it’s a bug then ill wait, i do not need a work around. If i did something wrong then tell me what i did wrong.

Thanks!

you did not have the proper arguments*

addOverlayCollection(…) method of builtins.KX_Scene instance
addOverlayCollection(KX_Camera *cam, Collection *col)

and about the ‘constructor’ it’s a cool idea really to test

addOverlayCollection(KX_Camera *cam, Collection *col)

Ok, looked at docs and can’t find this part, and to be honest i’m clueless about what to do here. Is it possible for you to make an example of it?

I agree, i’ve seen this in the docs and can be very useful, but to use that instead of a build-in option seems a bit odd to me. That’s why i just want to use the build-in option.

collection = bpy.data.collections[‘Name’]
cam= own.scene.objects['overlayCam]
own.scene.addOverlayCollection(cam, collection)

1 Like

Aah bpy.data, i was looking into bpy.types.

Thanks a lot got it to work, i find it a bit strange to make it work like this, need to getting used to it i guess. For the people who are figuring this out aswell, here is a .blend.

test.blend (853.3 KB)

The code used:

# uncheck all eye icons from the collection that you...
# want to have as an overlay, but keep the camera checked.

import bpy

def test(cont):
    
    own = cont.owner
    
    keyboard = cont.sensors['Keyboard']
    
    #check is needed to counter double activation
    if keyboard.positive:
        
        collection = bpy.data.collections['Hud']
        cam = own.scene.objects['hud_camera']
        
        own.scene.addOverlayCollection(cam, collection)
1 Like

Turns out if I add an overlay collection and I code the script to use the overlay collection’s camera, this will cause a momentary start freeze for a few seconds, and all objects lose their physics. If I do it with a non-hidden camera in the scene, objects won’t lose their physics, there is no frame drop or a starting freeze upon running. Is there an explanation for this?

EDIT: The collection doesn’t seem to display when I try to display it on a visible camera in the scene despite it being added to the camera as an overlay upon running. The camera is visible, and the overlay collection is hidden.

No clue at all, i don’t like the whole collection system that’s why i never made the jump to 3.0+, still using 2.5 myself.

there is a checkbox in the camera to get mouse over from ui camera

I would use 1 object for UI that is a object with geometry nodes,
each triangle gets replaced with a ui element,

all data about the element is stored in the face attributes for that triangle.

we can use bvhtree or 'reinstancePhysicsMesh(evaluated=True) to rayCast vs it after its updated