Logic on Profile grossly high

So I’m a newb and don’t know anything about anything so if you were me and when you checked your performance profile and your logic was at an astounding 55% what kinds of things would you look for to reduce that?

I know without looking at everything answers will be generalities but generalities will help me a good bit at this point

ok

anything you can store, do that

like for instance

running

Bob=scene.objects[‘Bob’]

every frame can be murder on a large scene,

it’s better to do,

import bge
cont=bge.logic.getCurrentController()
own=cont.owner

if 'Bob' not in own:
    own['Bob']=scene.objects['Bob']

else:
    do stuff

(this is with things that are always the same)

another trick

only run some things every 10 frames,

another trick, use states.

Can you isolate anything that is laggy?

we can help fix it,

another thing that is intense on logic, is setting things every frame that don’t need to be,

or ???

Thanks for the heads up. I will try those changes. Nothing in particular is bad. I assumed it was laggy because my models were too high poly but then I saw the logic being so crazy high. A lot of things are being checked at the same time so i’ll make adjustments.

if you would like, you could PM me a link, I can take a look for you,

(I promise not to share anything if you don’t want me to)

I’m not shy about my projects. I’d have to be a lot more impressed with my work for that.

right there

Ok,

Enemy AI,

Is that setting the Steering actuator target every frame?

it also seems to itterate through scene.objects every frame?

I think you need to logic set things every so often, then if the thing is changed run the python for some things,

like

Soldier

if target !=“Empty”-------------and-----------Navigate to target
if target is changed------------(set target)----/

and use other logic to set the path, occasionally,

So, you are basically programming the steering actuator to run instead of your script.

so when at target set own[‘Target’] =“Empty”

so this shuts down the steering actuator when not using it,

most items are probably on the every frame plan

now that you’ve said that’s a major concern I’ll try to redo all of them this week

so one trick,

label things with tags.

So instead of iterating scene.objects each frame,

have a “collector” that updates a list every 60 frames, the other objects grab a list from,

always 60---------------python




import bge
cont=bge.logic.getCurrentController()
Collector['EnemyList']=[]
for item in bge.logic.getCurrentScene().objects:
       if 'enemy' in item:
            add to enemy list

this way, each unit can grab the list collector’s object id on the first frame,


if 'Collector' not in own:
    own['Collector']=bge.logic.getCurrentScene().objects['Collector']
 

And then it’s already stored the list location so you can get at it later

EnemyList = own[‘Collector’][‘EnemyList’]

alright, thanks man. I’m off to bed. I’ll see what I can do on the morrow