actor cubes to no collision cubes

I deleted this.

####### digging
    ray_start = own.worldPosition
    ray_end = ray_start -own.worldOrientation.col[2] * 30.0
    ho,hp,hn = own.rayCast(ray_end,ray_start)
    if ho:
        if ho.name == "TheCube": 
            #ok we have intercepted the right cube
            # remove
            if bge.logic.mouse.events[bge.events.LEFTMOUSE] == 1:#click
                # let to the cubemanager of remove cube using the position of cube , not the cube direcly
                cm.free_position(ho.worldPosition) 
                # is veeery assumed that the cubes not moves for any reason 
            
            #duplicate
            elif bge.logic.mouse.events[bge.events.RIGHTMOUSE] == 1:
                cm.extrude_position(ho.worldPosition,hn) # position, normal 




modified this
def m(cont):
    own = cont.owner
    if not "cm" in own:
        own["cm"] = CubeManager(4)

######################### modified this

 own["cm"].set_distance(5.0) # warning to the correlation cube_size and distance,distance big = lag
        #own["cm"].free_position(own.worldPosition)
    cm = own["cm"]    
    cm.update_position(own.worldPosition)

Then i made a python script out of this.Because i wanted all the other cubes to be no collision except the ones near the player.And the error in the console is this.Here is the link to the last blend with the python code in it.

Read new prefs: C:\Users\barbara\AppData\Roaming\Blender Foundation\Blender\2.78\config\userpref.blend
found bundled python: C:\Program Files\Blender Foundation\Blender\2.78\python
read blend: C:\Users\barbara\Desktop\TESTVC2.blend


Blender Game Engine Started
Blender Game Engine Finished
Warning, sensor "Always" has lost a link to a controller (link 1 of 1) from object "metarig.002"
        possible causes are partially appended objects or an error reading the file,logic may be incorrect
Warning, sensor "Keyboard" has lost a link to a controller (link 1 of 1) from object "metarig.002"
        possible causes are partially appended objects or an error reading the file,logic may be incorrect
Warning, sensor "Keyboard.001" has lost a link to a controller (link 1 of 1) from object "metarig.002"
        possible causes are partially appended objects or an error reading the file,logic may be incorrect


Blender Game Engine Started
Blender Game Engine Finished


    
    
                
                

I don’t know what you wanted to achieve but I have a script to enable/disable physics for near/far objects

import bge

own = bge.logic.getCurrentController().owner
scene = bge.logic.getCurrentScene()
dist_to = own.getDistanceTo
dist_threshold = 10
for obj in scene.objects:
    if dist_to(obj) > dist_threshold:
        if obj.mass and not obj.isSuspendDynamics:
            obj.suspendDynamics()
    else:
        if obj.isSuspendDynamics:
            obj.restoreDynamics()

What is the framerate for 640,000?

If you have half a million cubes, its not wise to go through all of them every frame, duh…

You only need to consider the ones that are close to you or other actors. Actor_Count * 27 should be the number.

And as you keep the cubes in a grid you can easily check the surrounding cubes by a dictionary lookup.

something along the lines of

cube_dict[your_pos + Vector(-1,-1,-1)].doSomething()

I like marcoit’s python script for this better.Because i added a npc’s that dig a lot easier.And when i fall the ground will appear underneath.Since my computer is not that good.That is the best i can do.

I would advise you to reconsider your comment.

Those ideas are not exclusive. You can have both.

This sounds as you have inter-object logic connections - and you deleted one of the objects.

I’m curious if that happens while running the game. [The errors are not surrounded by the BGE status messages]

Yes it happens when in the bge.

Do you have inter-object connections (with objects called “metarig.002”)?

Yes i have logic bricks that go from Cube to metarig.002.It won’t work any other way.When the framerate drops below a certain point message sensors sending messages to message actuators do not work.

This does not put in error in the console.I put all the properties on the camera.Then put the controller in module mode for the script and it still does not work.What am i doing wrong?

from mathutils import Vector,Matrix
import bge
import random


THE_CUBE = bge.logic.getCurrentScene().objectsInactive["TheCube2"]
TYPE_TO_RGBA = {
"grass":(0.0,   1.0,    0.0,    1.0),
"wall": (0.2,   0.2,    0.3,    1.0),
"metal":(0.7,   0.7,    0.7,    1.0)
}




class VirtualCube2:
    pass


class VC(VirtualCube2):
    def __init__(self, position):
        self.position = Vector(position)
        self._inside = self._full = self._has_cube = False
        self.obj = None
        self.type = random.choice(["grass","wall","metal"])
        
    @property
    def inside(self):
        return self._inside
    @inside.setter
    def inside(self, inside):
        self._inside = bool(inside)
        self.has_cube = self.inside and self.full
    @property
    def full(self):
        return self._full
    @full.setter
    def full(self, full):
        self._full = bool(full)
        self.has_cube = self.inside and self.full


    @inside.setter
    def has_cube(self, has_cube):
        has_cube = bool(has_cube)
        if has_cube == self._has_cube:
            return
        self._has_cube = has_cube
        
        if has_cube:
            self.obj = bge.logic.getCurrentScene().addObject(THE_CUBE2, THE_CUBE2)
            self.obj.worldPosition = self.position.copy()
            self.obj.color = TYPE_TO_RGBA[self.type]
            
        else:
            obj = self.obj
            self.obj = None
            if obj and not obj.invalid:
                obj.endObject()
                if not self.full:
                    obj.scene.addObject("TheCubeDeath2",obj,10)
































class CubeManager:
    def __init__(self, cube_size=2):
        self.coord = None 
        self.cube_size = int(cube_size)
        self._distance = 0.0
        self.offsets = []
        self.inside_coords = set()
        self.set_distance(10)
        self.grid = {}
        self.potential_cubes = 0
        
        
    def chunky(self, pos):
        base = self.cube_size
        return tuple([round(v/base)*base for v in pos])


    def set_distance(self, dist):
        """require some reinitialization(cost a bit)"""
        if dist == self._distance:
            return
        dist = self._distance = float(dist)
        offsets = []
        amount = int(dist/self.cube_size)
        for x in range(-amount,amount+1):
            for y in range(-amount,amount+1):
                for z in range(-amount,amount+1):
                    offset = Vector((x,y,z))*self.cube_size
                    offsets.append(offset)
        
        self.offsets.clear()
        self.offsets.extend(offsets)
        if self.coord:
            self.refresh()
        self.potential_cubes = amount*amount*amount
        
    def free_position(self, pos):
        coord = self.chunky(pos)
        if not coord in self.grid:
            self.grid[coord] = VC(coord)
        self.grid[coord].full = False


    def fill_position(self, pos):
        coord = self.chunky(pos)
        if not coord in self.grid:
            self.grid[coord] = VC(coord)
        self.grid[coord].full = True
        
    def extrude_position(self, pos, direction):
        coord = self.chunky(pos)
        if not coord in self.grid:
            return
        if not self.grid[coord].full:
            return
        
        dr = Vector(direction).normalized()
        other_coord = self.chunky(Vector(coord)+dr*self.cube_size)
        if other_coord == self.coord:
            return
        if not other_coord in self.grid:
            self.grid[other_coord] = VC(other_coord)
        self.grid[other_coord].type = self.grid[coord].type
        self.grid[other_coord].full = True
        self.grid[other_coord].inside = True
        self.inside_coords.add(other_coord)


    def update_position(self, pos):
        assert len(pos) == 3
        if self.coord is None:
            self.free_position(pos) # where should be the player .. 


        coord = self.chunky(pos)
        if coord != self.coord:
            self.coord = coord
            self.refresh()


    def refresh(self):
        pos = Vector(self.coord)
        
        inside_coords = {self.chunky(pos+offset) for offset in self.offsets}
        for coord in inside_coords:
            if not coord in self.grid:
                self.grid[coord] = VC(coord)
                self.grid[coord].full = True
            self.grid[coord].inside = True
                


        for coord in self.inside_coords - inside_coords:
            self.grid[coord].inside = False
        self.inside_coords = inside_coords


        


def mo(cont):
    own = cont.owner
    if not "cm" in own:
        own["cm"] = CubeManager(4)
        own["cm"].set_distance(2.0) # warning to the correlation cube_size and distance,distance big = lag
        #own["cm"].free_position(own.worldPosition)
    cm = own["cm"]    
    cm.update_position(own.worldPosition)
    
    
    
    ### just for debug / stress test (how many cubes can be handled?)
    if bge.logic.mouse.events[bge.events.WHEELUPMOUSE] == 2:
        cm.set_distance(cm._distance*0.9)
    if bge.logic.mouse.events[bge.events.WHEELDOWNMOUSE] == 2:
        cm.set_distance(cm._distance*1.1)
    own["POTENTIAL_CUBES2"] = cm.potential_cubes # this is what can waste the rasterizer and also bullet
    own["tot_virtual_cubes2"] = len(cm.grid) # this can eventually waste the ram (can become a problem after a week of digging)
    ###############
    
    
    
    
    
    ####### digging
    ray_start = own.worldPosition
    ray_end = ray_start -own.worldOrientation.col[2] * 30.0
    ho,hp,hn = own.rayCast(ray_end,ray_start)
    if ho:
        if ho.name == "TheCube2": 
            #ok we have intercepted the right cube
            # remove
            if bge.logic.mouse.events[bge.events.LEFTMOUSE] == 1:#click
                # let to the cubemanager of remove cube using the position of cube , not the cube direcly
                cm.free_position(ho.worldPosition) 
                # is veeery assumed that the cubes not moves for any reason 
            
            #duplicate
            elif bge.logic.mouse.events[bge.events.RIGHTMOUSE] == 1:
                cm.extrude_position(ho.worldPosition,hn) # position, normal 
                
                
                
                
                
def mave(cont):
    own = cont.owner
    kev = bge.logic.keyboard.events
    accel = 1.5
    w, s, a, d = [kev[ord(k)]==2 for k in "wsad"]
    vel = own.localLinearVelocity
    vel.xy *= 0.9
    vel.y += (w-s) * accel
    vel.x += (d-a) * accel