CubeGrid.GetCubeBlock(POS) return null for non terminal blocks

Perforator Danio shared this bug 4 years ago
Reported

i write script for auto repairer drone.

and stuck on problem:

if (Control.CubeGrid.CubeExists(BlockPos))
            {
                Block = Control.CubeGrid.GetCubeBlock(BlockPos); //Returns null for Armor and other non terminal blocks
...
            }
For me it need for two scenario:

1) for calculate right center of masses for ships without IMyShipController module (if cockpit destroyed for example) because i dont know what type of block on position and dont know mass of this block

2) for get damage and missed components for repair ship after getting damage.


In decompilled libraries from game i see next code:

VRage.Game.ModAPI.Ingame.IMySlimBlock VRage.Game.ModAPI.Ingame.IMyCubeGrid.GetCubeBlock(
    Vector3I position)
{
    VRage.Game.ModAPI.Ingame.IMySlimBlock cubeBlock = (VRage.Game.ModAPI.Ingame.IMySlimBlock) this.GetCubeBlock(position);
    if (cubeBlock != null && cubeBlock.FatBlock != null && (cubeBlock.FatBlock is MyTerminalBlock && (cubeBlock.FatBlock as MyTerminalBlock).IsAccessibleForProgrammableBlock))
    return cubeBlock;
    return (VRage.Game.ModAPI.Ingame.IMySlimBlock) null;
}
Early (some years ago) this functional works fine and if IMySlimBlock will not been MyTerminalBlock - IMySlimBlock.FatBlock return null, but i can use IMySlimBlock.Mass, IMySlimBlock.CurrentDamage and IMySlimBlock.GetMissingComponents


Now this functional is not working.


Also i have problem to identitfy not 1x1x1 size (non Terminal) blocks because i cannot determine size of block, block type, block hash and orientation.


Fix it please! I need this functional.

Replies (6)

photo
1

Hello, Engineer!


Thank you for your feedback! Your topic has been added between considered issues.

Please keep voting for the issue as it will help us to identify the most serious bugs.


We really appreciate your patience.


Kind Regards

Keen Software House: QA Department

photo
1

... 10 months without a fix or an explanation. Thank you ... I just spent 12 hours building something, last 3 hours debugging ... just to end up here and realize you don't care :/

photo
1

Hello!


Thank you for letting us know that this is still an issue. I'm moving this ticket to Submitted for further investigation.


Kind Regards

Keen Software House: QA Department

photo
photo
1

Hello, Engineers!

Is there any way how you can show me in game itself? Does the non-functional script influence some grid/block not to work properly? The original text is speaking about self-repairing drone. Is it same case for you? If yes, can you please share the BP of the drone and the script itself as well? That would be the best way to start with. Or maybe whole save file might be the best, so I can just load it and try/see it on my own.

You can access your save files by typing %appdata% into your Windows search bar and you will be redirected to the hidden Roaming folder. After that just follow: \Roaming\SpaceEngineers\Saves. There should be a folder with your SteamID and your saves.

Please zip the file and attach it here. If you are having difficulty attaching files you can optionally use Google Drive. When sharing a google drive link please make sure it is set to be downloadable by anyone with the link.

Thanks in advance for providing requested files.

Kind Regards

Keen Software House: QA Department

photo
1

Hello, the API simply doesn't work as expected, and the issue is really simple:

- CubeGrid.CubeExists returns true

- CubeGrid.GetCubeBlock returns null (ergo cube doesn't exist).


Here is a simple demonstration: https://steamcommunity.com/sharedfiles/filedetails/?id=2421215065

Just hit the Run button in PB and see the output.


Here is the code for reference:

var worldPosBellow = Me.WorldMatrix.Translation + Me.WorldMatrix.Down * 3;
var posBellow = Me.CubeGrid.WorldToGridInteger(worldPosBellow);

Echo("PB position: " + Me.Position);
Echo("Somewhere bellow: " + posBellow);
Echo("");

if (Me.CubeGrid.CubeExists(posBellow)) {
    Echo("Yes, there is some block bellow the PB");
}

if (Me.CubeGrid.GetCubeBlock(posBellow) == null) {
    Echo("...but apparently there isn't. GetCubeBlock returns null");
}

photo
2

Hello, Jakub,

thanks for making the example. Like this, the issue was easily and successfully reproduced. I put it into our internal system.

Kind Regards

Keen Software House: QA Department

photo
1

Still nothing has changed. If you want to preserve backwards compatibility, then just add a parameter with a default. It really should be extremly simple:

VRage.Game.ModAPI.Ingame.IMySlimBlock VRage.Game.ModAPI.Ingame.IMyCubeGrid.GetCubeBlock(
    Vector3I position, bool null_for_slim = true)
{
    VRage.Game.ModAPI.Ingame.IMySlimBlock cubeBlock = (VRage.Game.ModAPI.Ingame.IMySlimBlock) this.GetCubeBlock(position);
    if (cubeBlock != null && ((cubeBlock.FatBlock != null && (cubeBlock.FatBlock is MyTerminalBlock && (cubeBlock.FatBlock as MyTerminalBlock).IsAccessibleForProgrammableBlock)) || !null_for_slim))
    return cubeBlock;
    return (VRage.Game.ModAPI.Ingame.IMySlimBlock) null;
}
One could do some neat stuff, if one had access to that information.

Leave a Comment
 
Attach a file