big lag, caused by mouse over?

i made a block based building system but it seems to be too laggy, every cube has 12 mouse over sensors(2 per face), but the strange thing is that when im not hovering the mouse over the cubes, the game runs at 60 fps, but when i move the mouse over a cube, the fps goes down to less than 10, is there a way to solve this? maybe replacing the mouse over stuff with a python script?

Im kind of a noob here. But 12 mouseovers per cube seems a bit extreme, and you got a lot of cubes there, and really i dont know why you would have to have 2 mouseover sensors per face…if youll look at your 1st screenshot, your logic is 92%…Can you explain what your trying to do so what we can get a better handle on how to help.

yes, the main idea is that when you click on a face, you add a cube in that face you clicked, so there you have 1 mouseover per face to add a cube, and another mouse over(on inverse mode) to display the black reticule arround the cube or make the reticule invisible

Well, here is where you meet the limitations of logic bricks. They’re fine for smaller or simpler projects, but for more complex functions like this, you’ll need Python to get rid of the drain on your FPS. Are you familiar with it at all?

The problem is with the “Mouse Over” logic brick. It doesn’t work well with a large number of objects. Use “Mouse Over Any” and use a Python script to handle the event. In my experience, this will cause unbelievable improvements in speed.

(The other possibility is that “Mouse Over” doesn’t work well with high polygon objects… but I would hope you don’t have any high polygon objects in a block based building system.)

As blendenzo writes, the MouseOverSensor is not “optimized” it sends a ray with each MouseOverSensor at each frame. This is hard work for the Physics engine.

The MouseOverAny sensor is a solution as long as there are only a few of them.

I usually use only one MouseOverAny connected to a script, and then get the hit object and have the script handle the click event based on what that object is.

Just use the usePulseFocus attribute of the mouseOverAny sensor to make it trigger each time it mouses over a “new” object.

hi! i have been sleeping thats why i didnt answer :stuck_out_tongue: well basicly i cant do that as i have no python knowledge (so i will try to get some tutorial for this, thanks for the help everyone!

Here’s my idea:
Use the pulseFocus attribute to make the mouse sensor trigger only when the object under the mouse changes.
When it changes, it will trigger positive. Get the hitnormal of the sensor, and the object it senses. Then you can determine which face was hit. Then you can take the normal vector, and multiply it by a scalar to get an offset vector from the object. Add that vector to the object’s position to determine where to add the cube.

import bge

def mouse_add(cont):
    own = cont.owner
    scene = bge.logic.getCurrentScene()
    mouse = cont.sensors[0]

    if not mouse.positive:

    offset = 5.0    

    hit_object = mouse.hitObject
    hit_normal = mouse.hitNormal

    new_position = hit_object.worldPosition + (hit_normal * offset)
    brick = scene.addObject("Cube", own)
    brick.worldPosition = new_position

thanks agoose, but how should i set up the logic bricks for this script?
sorry for my complete python newbieness :o

Mesh1.blend (382 KB)
How about this?

oh wow thats great, and with a very good fps, thanks agoose :smiley:

of course python is ever much more fast than brick .
not only in this “extreme case” … ever :slight_smile:

well done agoose :wink:

i have another question about this, is there a way to make the script handle more than just one block?, i think it can be adding a property, and depending on that property, the block the script adds, this way, it can be much easier to add more blocks
prop = 1 add grass block
prop = 2 add wood block
prop = 3 add rock block
and like this…

i have update the code
move the wheel up/down to change block type

def mouse_add(cont):
    own = cont.owner
    scene = bge.logic.getCurrentScene()
    mouse = cont.sensors['Over']
    click = cont.sensors['Add']
    if not "init" in own:
        own["init"] = 1
        L = ["blockGrass", "blockStone", "blockPlastic",] # <- add the name of other cube here
        own["blocks"]=[0, L]
    if mouseEv[] == 1 :
        v = own["blocks"]
        v[0] -= 1
        if v[0] < 0 :
            v[0] = len(v[1]) - 1
    if mouseEv[] == 1 :
        v = own["blocks"]
        v[0] += 1
        if v[0] >= len(v[1]) :
            v[0] = 0
    own["prop"] = own["blocks"][1][own["blocks"][0]]
    active = mouse.positive and click.positive
    if not active:

    offset = 2.0    

    hit_object = mouse.hitObject
    hit_normal = mouse.hitNormal
    typeBlock = own["blocks"][1][own["blocks"][0]]
    brick = scene.addObject(typeBlock, own)
    brick.worldPosition = hit_object.worldPosition + (hit_normal * offset)

but need also an always sensors True (to avoid annoyng stop of logic :no:)
and one property to see the type of block to add


Mesh1b.blend (82.1 KB)

nice thanks! i hope to learn python soon so im not depending always of the blender artist community :o

no problem :wink: , the forum exist for this reason!! :wink:

i edited some of it my self and i tried to make it so you could spawn lights but when you do more than one it gets all weird any one know how to fix it?


bc.blend (1.03 MB)