Mouse Cursor over object dramatically reduces Frame rate in-game

Hi,

I have been silently tinkering away with developing a rather small game over 5-6 months solid.

Just about every problem I have encountered in developing this game I have eventually overcome.

I have refrained from asking questions until now and I can’t seem to find anything specific to this topic.

My game is strange and not typical for BGE in some ways. Because of this I have had (in some cases) a very

difficult time, figuring out an adaptation method for what I was trying to accomplish. I’m out of leads here…

With all that behind me, UV editing, snapping, animating, extensive logic bricking, scene appending, why I can’t animate

the “emit” value of a mat with key frames (found work-around) and basically loads of other little things.

I have one room, with one machine consisting of over 250 little nails, roughly 64,000 faces in this scene.

There are a few mouse-over sensors in objects within the machine but I get huge logic spikes when I move the

mouse cursor over areas that don’t even have mouse sensors, and if anything a few simple logic bricks.

I go from 60 FPS (cursor out of game window) to about 20 FPS (cursor over machine) and even down to 5-10 FPS

If the cursor is out of the game window, its all good.

It is a complex area with a lot of objects but am I not removing something that I should be?

This has been going on for a while. At first I thought it was related to objects I was using a lot of controller expressions

in.

There are objects within the setup that do have a lot of Boolean properties that are and being using to perform

actions to make a specific object “left clickable” only when the mouse is over it.

Additionally I figured out how to setup a separate title screen and I have a small non-functional display machine rotating

back and fourth off a repeating delay. I have removed all the logic out of this smaller machine and I still get crazy lag

with the mouse cursor over it.

I’m thinking its because of all the objects? Needs to pass some sort of detection? What is this sorcery! Blender, its not THAT difficult, she’s like a genie in a bottle… just gotta rub her the right way.

Should I start the rub from the right or left? Diagonally or horizontally?

XD

Thanks for any help/insight!

Unfortunately each mouse over sensor uses a ray to sense what is under the mouse cursor. This means as more sensors you have as more processing time is eaten. This issue is already raised, but for now you have to live with it.

A good workaround is to have a single mouse over any sensor, that checks what is under the mouse cursor and notifies exactly this object (e.g. via message or via property). You need a bit of Python to do this. I’m sure you will get much help here.

Unfortunately each mouse over sensor uses a ray to sense what is under the mouse cursor. This means as more sensors you have as more processing time is eaten. This issue is already raised, but for now you have to live with it.

A good workaround is to have a single mouse over any sensor, that checks what is under the mouse cursor and notifies exactly this object (e.g. via message or via property). You need a bit of Python to do this. I’m sure you will get much help here.

Remark: Your post would be better to read with less blank lines ;).

as say Monster the solution will be use one mouseOverAny .

somthing like this :


import bge


class mouseOverAny:
    def __init__(self):
        self._hitObject = None
        self._hitPosition = None
        self._hitNormal = None
        scene_pre_draw.append(self.update) # this work only in the current scene
        # bge.runAlways.append(self.update) will be perfect but not exist
        
    def update(self):
        cam = bge.logic.getCurrentScene.active_camera
        vec = cam.getScreenVect(*bge.logic.mouse.position) * -1
        self._hitObject, self._hitPosition, self._hitNormal = cam.rayCast(cam.worldPosition + vec, cam, 9999999999999)
    
    @property
    def hitObject(self):
        return self._hitObject
    
    @property
    def hitPosition(self):
        return self._hitPosition
    
    @property
    def hitNormal(self):
        return self._hitNormal
    
try:
    x = bge.render.mouseOverAny
except : #to run only once!
    bge.render.mouseOverAny = mouseOverAny()
    




now ton s of sensors can reference to bge.render.mouseOverAny, with a fast check..


## sensor mouse Over
if bge.render.mouseOverAny.hitObject == self.owner : 
    self.trigger = True 
    self.etc .. =
    
## sensor mouse Over Any
if bge.render.mouseOverAny.hitObject : 
    self.trigger = True 
    self.etc .. =
    
    

 
>def update
>9999999999999
>try: except:

Is that really necessary? :stuck_out_tongue:

Oh well. Maybe OP could also consider whether he needs to check mouseover at every frame as the mouse moves? You could make the system much more responsive if you could do with checking mouseover only with mouse click.

If what you have is result of a learning process with lots of figured out sort-of solutions there could be something else worth optimizing as well.

999999999 afaik is necessary otherwise make a ray point-to-point(1 meter),
try/except probably not, is a sort of advice…

as optimization,
only control the mouse position is insufficient,
you should check if there’s been any change (position / rotation / scale) for each object

however, with the old code
there was always a ray running , even though no one had called him
it was actually a bit annoying

so I tried to remove it by adding some quick checking.
so, in this case the ray is done on the fly
no ray is done if anyone call it.
to avoid double excecution there a sort of timer

this time is extremely optimized , for my abilities.

see if you can add some other optimization :slight_smile:

PS:in the second layer there a “normal mouseOver” for comparison

Attachments

moa_extremeOptimization.blend (196 KB)

Roger that, the spaces defeated their purpose!
You guys are the bombs! I will have to look into the mouse over any code below.
Just need to figure out how to use this. Checking out the .blend

Thanks so much!

This is for a 3D nail with a second ghost highlighting nail (bright color). The highlighter nail is bigger but behind a static main nail. Highlighter just displays what nail you have selected. I had an extra inverted mouse over sensor in six nails. I needed it back when I knew less cause that’s what worked. Understanding much more but that “not mouse over signal” which the excess inverted mouse over sensor was replaced with the appropriate method. I found I can run an AND & NAND cont. block off the one sensor to obtain the same function, with far better results.

 If the literal coding method is faster overall I'd prefer that because I would like to have this on about 200 + nails. 

The demo you provided along with the normal method might just be enough!

TY!