0
$\begingroup$

I have implemented a custom mouse pointer in a separate scene. It mostly works fine as a mouse pointer, however when it is used as a overlay scene for my main game world, the logic shoots up to around 180-300ms when it hovers over the objects in the scene, however, goes down to a normal 1-4ms when it is pointed at the sky. Any ideas of how i can decrease this logic use so the frame-rate doesn't suffer?

Here is the logic setup and the simple python script (i'm still very new to python): enter image description here

enter image description here

$\endgroup$
  • $\begingroup$ Please upload a demo blend file to investigation. The information above is not enough to see the bottleneck. $\endgroup$ – Monster Mar 14 '18 at 6:51
  • $\begingroup$ The main world scene is just called 'World', and the custom cursor scene is called 'Cursor.001' : drive.google.com/open?id=1_elhKtiDyB4x4rX2r0gtO9Ao1Qjl1ujP $\endgroup$ – Heavyhand Mar 14 '18 at 10:09
2
$\begingroup$

Some things I found:

You should be more carefully with the usage of [True Level Triggering]

Just by deactivating [True Level Triggering] at Sensor "Always" of object Camera.001 the logic time improved from 5 ms to 0.05 ms.

Analysing the Game scene

Your scene has quite a lot of objects. I ran my analyser to get some information from it's setup:

Keyboard Listeners (Sensors):

----------------------------------------------------------
purpose <keys> by scene.gameObject (purpose = sensor name)
----------------------------------------------------------
a                           <a>             by World.Arrow.007
d                           <d>             by World.Arrow.007
a                           <a>             by World.Arrow.003
d                           <d>             by World.Arrow.003
a                           <a>             by World.Arrow.002
d                           <d>             by World.Arrow.002
w                           <w>             by World.Movement
shift                       <LEFTSHIFTKEY>  by World.Movement
a                           <a>             by World.Movement
d                           <d>             by World.Movement
s                           <s>             by World.Movement
space                       < >             by World.Movement
w.001                       <w>             by World.Movement
shift.001                   <LEFTSHIFTKEY>  by World.Movement
a.001                       <a>             by World.Movement
d.001                       <d>             by World.Movement
s.001                       <s>             by World.Movement
w.002                       <w>             by World.Movement
shift.002                   <LEFTSHIFTKEY>  by World.Movement
a.002                       <a>             by World.Movement
d.002                       <d>             by World.Movement
s.002                       <s>             by World.Movement
Keyboard                    <F2KEY>         by World.Movement
Keyboard.001                <F2KEY>         by World.Movement
Keyboard.002                <w>             by World.Movement
Keyboard.003                <s>             by World.Movement
Keyboard.004                <a>             by World.Movement
Keyboard.005                <d>             by World.Movement
Ctrl                        <LEFTCTRLKEY>   by World.Camera.009
Ctrl                        <LEFTCTRLKEY>   by World.Camera
Ctrl                        <LEFTCTRLKEY>   by World.Camera.008
w                           <w>             by World.metarig.002
shift                       <LEFTSHIFTKEY>  by World.metarig.002
s                           <s>             by World.metarig.002
not w.001                   <w>             by World.metarig.002
shift.002                   <LEFTSHIFTKEY>  by World.metarig.002
w.001                       <w>             by World.metarig.002
not shift                   <LEFTSHIFTKEY>  by World.metarig.002
w.002                       <w>             by World.metarig.002
not w                       <w>             by World.metarig.002
not s                       <s>             by World.metarig.002
Space                       < >             by World.metarig.002
Space.002                   < >             by World.metarig.002
Space.003                   < >             by World.metarig.002
Space.004                   < >             by World.metarig.002
not a                       <a>             by World.metarig.002
a                           <a>             by World.metarig.002
a.001                       <a>             by World.metarig.002
d                           <d>             by World.metarig.002
not d                       <d>             by World.metarig.002
d.001                       <d>             by World.metarig.002
a                           <a>             by World.Q battery
d                           <d>             by World.Q battery
a                           <a>             by World.Arrow
d                           <d>             by World.Arrow
a                           <a>             by World.Q Egg
d                           <d>             by World.Q Egg
a                           <a>             by World.Q seeds
d                           <d>             by World.Q seeds
a                           <a>             by World.Q.001
d                           <d>             by World.Q.001
a                           <a>             by World.Q.002
d                           <d>             by World.Q.002
Print Active game objects   <a>             by World.Analyzer__
Print Inactive game objects <i>             by World.Analyzer__
Print active Controllers    <c>             by World.Analyzer__
Print Python controllers    <p>             by World.Analyzer__
Print Message listeners     <m>             by World.Analyzer__
Print Keyboard listeners    <k>             by World.Analyzer__
Help                        <h>             by World.Analyzer__
Print Message Senders       <s>             by World.Analyzer__

warning: scene Cursor.001 already exists, not added!
warning: scene Cursor.001 already exists, not added!
warning: scene Seasons.001 does not exist, not removed!
warning: scene Seasons.001 does not exist, not removed!
warning: scene Seasons.001 does not exist, not removed!
Message Listeners (Sensors):
----------------------------
scene.gameObject: subject
----------------------------
World.Cube.057:           Net
World.Net.003:            Net
World.Net.002:            Net
World.Net.001:            Net
World.Key.005:            Igloo egg
World.Key.004:            Igloo egg
World.Key.003:            Igloo egg
World.Key.002:            Igloo egg
World.Gate.003:           Open door
World.Cube.043:           Key
World.Cube.042:           Key
World.Gate.002:           Open door
World.Gate.001:           Open door
World.Cube.041:           Key
World.Cube.040:           Key
World.Cube.038:           Igloo egg
World.Plane.039:          Fried egg
World.Cylinder.011:       Cook
World.Empty.007:          Egg
World.Empty.007:          Pan
World.Empty.006:          Wood pick
World.Empty.006:          Flint
World.Cylinder.010:       Fire time
World.Cube.027:           Bird seeds
World.Bird.001:           Bird seeds
World.Plane.038:          Seeds got
World.Plane.037:          Bird seeds
World.Egg.003:            Egg
World.Egg.002:            Egg
World.Egg.001:            Egg
World.Point.010:          Fire
World.Plane.021:          Igloo egg
World.Arrow.007:          Battery
World.Arrow.007:          Log cut
World.Arrow.007:          Stop
World.Arrow.007:          Resume
World.Arrow.006:          Axe
World.Arrow.006:          Log cut
World.Arrow.005:          Axe
World.Arrow.005:          Log cut
World.Arrow.004:          Axe
World.Arrow.004:          Log cut
World.Plane.011:          Power
World.Melon SLICE.003:    Cut melon
World.Melon SLICE.002:    Cut melon
World.Melon SLICE.001:    Cut melon
World.Sound:              Axe
World.Sound:              Battery
World.Sound:              Power
World.Sound:              Wood pick
World.Sound:              Log cut
World.Sound:              Cut melon
World.Sound:              Seeds
World.Arrow.003:          Battery got
World.Arrow.003:          Power
World.Arrow.003:          Stop
World.Arrow.003:          Resume
World.Cylinder:           Battery got
World.Arrow.002:          Log cut
World.Arrow.002:          Axe got
World.Cube:               Axe got
World.T pad.001:          Power
World.Movement:           Summer
World.Movement:           Tel W
World.Movement:           Winter
World.Movement:           Tel S
World.Movement:           Spring
World.Movement:           Tel Sp
World.Movement:           Autumn
World.Movement:           Tel A
World.Movement:           Stop
World.Movement:           Resume
World.Empty:              Stop
World.Empty:              Resume
World.Camera.009:         Summer
World.Camera.009:         Winter
World.Camera.009:         Spring
World.Camera.009:         Autumn
World.Camera.009:         Power
World.Camera.009:         Farm
World.Camera.009:         No farm
World.Camera:             Summer
World.Camera:             Winter
World.Camera:             Spring
World.Camera:             Autumn
World.Camera:             Power
World.Camera:             Tel W
World.Camera:             Tel Sp
World.Camera:             Tel A
World.Camera.008:         Summer
World.Camera.008:         Winter
World.Camera.008:         Spring
World.Camera.008:         Autumn
World.Camera.008:         Power
World.Camera.008:         Tel W
World.Camera.008:         Tel Sp
World.Camera.008:         Tel A
World.metarig.002:        Stop
World.metarig.002:        Resume
World.Gate:               Open door
World.Q battery:          Power
World.Q battery:          Stop
World.Q battery:          Resume
World.Arrow:              Axe
World.Arrow:              Stop
World.Arrow:              Resume
World.Arrow.001:          Axe
World.Arrow.001:          Log cut
World.Wood:               Log cut
World.Melon SLICE:        Cut melon
World.Butterfly 2:        Butterfly
World.Icosphere.048:      Net
World.T pad.005:          Power
World.Q Egg:              Igloo egg
World.Q Egg:              Stop
World.Q Egg:              Resume
World.Spider:             Spider
World.Empty.001:          Fire
World.Egg:                Egg
World.Bird:               Bird seeds
World.Q seeds:            Bird seeds
World.Q seeds:            Stop
World.Q seeds:            Resume
World.Seeds.001:          Bird seeds
World.Key:                Igloo egg
World.Q.001:              Fire
World.Q.001:              Stop
World.Q.001:              Resume
World.Q.002:              Fried Egg
World.Q.002:              Fire
World.Q.002:              Stop
World.Q.002:              Resume
World.Net:                Net
Toolbar.001.Text.032:     Butterfly
Toolbar.001.Text.031:     Caterpillar
Toolbar.001.Text.030:     Spider
Toolbar.001.Text.015:     Net
Toolbar.001.Axe.001:      Axe
Toolbar.001.Battery.001:  Battery
Toolbar.001.Battery.001:  Power
Toolbar.001.Cylinder.005: Wood pick
Toolbar.001.Cylinder.005: Fire
Toolbar.001.Seeds:        Seeds
Toolbar.001.Seeds:        Bird seeds
Toolbar.001.Egg.004:      Egg
Toolbar.001.Egg.004:      Fried egg
Toolbar.001.Egg.004:      Fire
Toolbar.001.Pan.001:      Pan
Toolbar.001.Pan.001:      Flint
Toolbar.001.Pan.001:      Fried egg
Toolbar.001.Pan.001:      Fire
Toolbar.001.Flint:        Flint
Toolbar.001.Flint:        Fire
Toolbar.001.Fried egg:    Fried egg
Toolbar.001.Fried egg:    Igloo egg
Toolbar.001.Key.001:      Key
Toolbar.001.Key.001:      Open door
Toolbar.001.Net.004:      Net
Toolbar.001.Spider.001:   Spider
Toolbar.001.Butterfly:    Butterfly
Toolbar.001.Cylinder.013: Caterpillar
Title.Plane.002:          Power
Menu game.Empty.002:      Game control
Menu game.Empty.002:      Resume
Menu game.Plane.057:      Resume
Menu game.Text.022:       Resume
Menu game.Plane.053:      Resume
Menu game.Text.029:       Control show
Menu game.Text.029:       Control hide
Menu game.Text.028:       Control show
Menu game.Text.028:       Control hide
Quests.Plane.060:         Quest show
Quests.Plane.060:         Quest hide
Quests.Plane.065:         Power
Quests.Plane.065:         Tel A
Quests.Plane.065:         Tel Sp
Quests.Plane.065:         Tel W
Quests.Plane.064:         Battery
Quests.Plane.064:         Tel A
Quests.Plane.064:         Tel Sp
Quests.Plane.064:         Tel W
Quests.Plane.063:         Log cut
Quests.Plane.063:         Tel A
Quests.Plane.063:         Tel Sp
Quests.Plane.063:         Tel W
Quests.Plane.062:         Near log
Quests.Plane.062:         Tel A
Quests.Plane.062:         Tel Sp
Quests.Plane.062:         Tel W
Quests.Plane.061:         Axe
Quests.Plane.061:         Tel A
Quests.Plane.061:         Tel Sp
Quests.Plane.061:         Tel W
Quests.Text.040:          Tel A
Quests.Text.040:          Tel Sp
Quests.Text.040:          Tel W
Quests.Text.040:          Power
Quests.Text.039:          Tel A
Quests.Text.039:          Tel Sp
Quests.Text.039:          Tel W
Quests.Text.039:          Battery
Quests.Text.037:          Tel A
Quests.Text.037:          Tel Sp
Quests.Text.037:          Tel W
Quests.Text.037:          Log cut
Quests.Text.036:          Tel A
Quests.Text.036:          Tel Sp
Quests.Text.036:          Tel W
Quests.Text.036:          Near log
Quests.Text.035:          Tel A
Quests.Text.035:          Tel Sp
Quests.Text.035:          Tel W
Quests.Text.035:          Axe
Quests.Text.034:          Tel A
Quests.Text.034:          Tel Sp
Quests.Text.034:          Tel W
Quests.Empty.000:         Quest
Toolbar.001.Text.032:     Butterfly
Toolbar.001.Text.031:     Caterpillar
Toolbar.001.Text.030:     Spider
Toolbar.001.Text.015:     Net
Toolbar.001.Axe.001:      Axe
Toolbar.001.Battery.001:  Battery
Toolbar.001.Battery.001:  Power
Toolbar.001.Cylinder.005: Wood pick
Toolbar.001.Cylinder.005: Fire
Toolbar.001.Seeds:        Seeds
Toolbar.001.Seeds:        Bird seeds
Toolbar.001.Egg.004:      Egg
Toolbar.001.Egg.004:      Fried egg
Toolbar.001.Egg.004:      Fire
Toolbar.001.Pan.001:      Pan
Toolbar.001.Pan.001:      Flint
Toolbar.001.Pan.001:      Fried egg
Toolbar.001.Pan.001:      Fire
Toolbar.001.Flint:        Flint
Toolbar.001.Flint:        Fire
Toolbar.001.Fried egg:    Fried egg
Toolbar.001.Fried egg:    Igloo egg
Toolbar.001.Key.001:      Key
Toolbar.001.Key.001:      Open door
Toolbar.001.Net.004:      Net
Toolbar.001.Spider.001:   Spider
Toolbar.001.Butterfly:    Butterfly
Toolbar.001.Cylinder.013: Caterpillar
Title.Plane.002:          Power
Tip Farm.Text.001:        Show farm
Tip Farm.Text.001:        Hide farm
Tip Farm.Text.001:        Show farm
Tip Farm.Text.001:        Hide farm
Toolbar.001.Text.032:     Butterfly
Toolbar.001.Text.031:     Caterpillar
Toolbar.001.Text.030:     Spider
Toolbar.001.Text.015:     Net
Toolbar.001.Axe.001:      Axe
Toolbar.001.Battery.001:  Battery
Toolbar.001.Battery.001:  Power
Toolbar.001.Cylinder.005: Wood pick
Toolbar.001.Cylinder.005: Fire
Toolbar.001.Seeds:        Seeds
Toolbar.001.Seeds:        Bird seeds
Toolbar.001.Egg.004:      Egg
Toolbar.001.Egg.004:      Fried egg
Toolbar.001.Egg.004:      Fire
Toolbar.001.Pan.001:      Pan
Toolbar.001.Pan.001:      Flint
Toolbar.001.Pan.001:      Fried egg
Toolbar.001.Pan.001:      Fire
Toolbar.001.Flint:        Flint
Toolbar.001.Flint:        Fire
Toolbar.001.Fried egg:    Fried egg
Toolbar.001.Fried egg:    Igloo egg
Toolbar.001.Key.001:      Key
Toolbar.001.Key.001:      Open door
Toolbar.001.Net.004:      Net
Toolbar.001.Spider.001:   Spider
Toolbar.001.Butterfly:    Butterfly
Toolbar.001.Cylinder.013: Caterpillar
Title.Plane.002:          Power

active and frequently triggered Python controllers in this frame
----------------------------------------------------------------
scene.gameObject(controller) by sensors
----------------------------------------------------------------
scene Cursor.001:       Mouse.001|Python         by [over, Mouse, Mouse.001]

This output might help you later. Unfortunately I have no function that prints all mouse sensors to console. When you have many mouse over sensors it will constantly eat performance. But let me check how many you have...

It does not look like you have too much. But it is hard to say.

Cursor Script

You suspected that your cursor script is the bottleneck. I can't confirm that. When I disable the cursor controller (and enable the system mouse cursor) the processing time does not improve.

Mouse Over Sensor

I have a different idea. This requires that I explain to you how the mouse over sensor is working.

The mouse over sensor (and the mouse over any sensor too) is basically a ray sensor. It measures the line under the system mouse cursor from pretty near the camera to pretty far away from the camera. This "ray" is a measurement of the line trying to find any face it crosses.

This is a pretty heavy operation which gets worse with the number of objects and faces that exist in the scene. To be more specific what matters are the physics faces (ghost and no collision objects will be ignored and not considered = no processing time required).

The nature of a sensor is that it will measure at each single frame. All sensor types do that. This means when a single measure eats time it will eat that time at each single frame until the sensor dies ( because the owning object died).

As more sensors you have as more processing time is required. As all mouse over sensors are measuring along the same line (the line under the cursor) you might think that only one measure is calculated within a single frame. Unfortunately this is not the case. Each mouse over sensor measures again. That is the reason why the number of such sensors should be as low as possible.

So there are two thing to consider:

  • the number of mouse over sensors
  • the number of "detectable" faces (including face that can block the measurement)

Reduce the number of detectable faces

I switched on Game\Show Physics Visualization. It showed my there are quite a lot of very detailed objects on the screen. They are not visible, but present as physics objects. These objects might cause the bottleneck. I suggest when you do not need them (they look like menu entries), then move them outside of the camera's view. This way the mouse over sensor does not need to consider them.

Reduce the number of sensors

To reduce the number of mouse over sensors you can use a single mouse over any sensor connected to a Python controller. The Python controller can read the object under the cursor (it should be one per scene) and tell interested objects which one it is. This reduces the number of mouse over sensor to one per scene.

Please be aware this is only worth when you have more than ~10 mouse over sensors.

I hope this helps a bit. Due to the large size of your scenes I can't dig deeper right now.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.