[1.189.0] [In-game scripts] IMyInventory.IsConnectedTo caches responses.

Bartosz C. shared this bug 3 years ago

It looks like the method VRage.Game.ModAPI.Ingame.IMyInventory.IsConnectedTo is caching its responses per block and in consequence returns wrong results after first use.

I've made a setup with three basic refineries: "Refinery A", "Refinery B" and "Refinery C".

"Refinery A" is connected to "Refinery B" by conveyor tube.

"Refinery C" stands alone.

Then I've executed the following code in a programmable block:

public void Main(string argument, UpdateType updateSource)
    const string nameA = "Refinery A", nameB = "Refinery B", nameC = "Refinery C";

    var a = (IMyRefinery)GridTerminalSystem.GetBlockWithName(nameA);
    var b = (IMyRefinery)GridTerminalSystem.GetBlockWithName(nameB);
    var c = (IMyRefinery)GridTerminalSystem.GetBlockWithName(nameC);
    var aInv = a.InputInventory;
    var bInv = b.InputInventory;
    var cInv = c.InputInventory;

    Echo(a.CustomName + (aInv == null ? " ERR" : " OK"));
    Echo(b.CustomName + (bInv == null ? " ERR" : " OK"));
    Echo(c.CustomName + (cInv == null ? " ERR" : " OK"));

    Echo(aInv.IsConnectedTo(bInv) ? "a to b connected" : "a to b not conn.");
    Echo(aInv.IsConnectedTo(cInv) ? "a to c connected" : "a to c not conn.");

    Echo(bInv.IsConnectedTo(aInv) ? "b to a connected" : "b to a not conn.");
    Echo(bInv.IsConnectedTo(cInv) ? "b to c connected" : "b to c not conn.");

    Echo(cInv.IsConnectedTo(aInv) ? "c to a connected" : "c to a not conn.");
    Echo(cInv.IsConnectedTo(bInv) ? "c to b connected" : "c to b not conn.");

The output was:

Refinery A OK
Refinery B OK
Refinery C OK
a to b connected
a to c connected
b to a connected
b to c connected
c to a not conn.
c to b not conn.

The output tells that "Refinery A" is connected to "Refinery C" and "Refinery B" is also connected to "Refinery C" which is wrong.Changing order in which the IsConnectedTo is called gives different results.

Space Engineers version: 1.189.040 default

Replies (5)


Here is a world that demonstrates the bug:


Run the PB script and check the echo. ExpectedResult: ActualResult


I had this also. My transfer function checks this before attempting transfers, building something like a refinery that's not connected to anything stops all transfers and my script returns that nothing is connected.


Hello, Engineers!

Thank you for reporting this issue. We have been able to reproduce it and it is forwarded to programmers team.

Kind Regards

Keen Software House: QA Department


IMyInventory.CanTransferItemTo() also dosn't work. I hope this will be fixed soon.


That function works for me and the ~thousand people who use my script haven't reported it as not working for them. If that function returns negative, it doesn't transfer anything and it outputs "ITEM cannot be transferred from CONTAINER to CONTAINER".

I have seen it return negative a few times, but I believe the container was full or it didn't have a conveyor connection.


Ive got this behavior:

Test case A:

Container A - Conveyor Tube - Container B (empty) => CanTransferItemTo() = true

(removing the tube)

Container A - <no connection> - Container B (empty) => CanTransferItemTo() = false

Everything is fine here.

Test case B: (Container A has 2 connected tubes)

Container A - Conveyor Tube - Container B (empty) = CanTransferItemTo() -> true

Container A - Conveyor Tube - Container C (empty) = CanTransferItemTo() -> true

(removing one of the tubes)

Container A - <no connection> - Container B (empty) = CanTransferItemTo() -> false

Container A - Conveyor Tube - Container C (empty) = CanTransferItemTo() -> false (this is wrong)

Tested in SP and MP

Here is the Test Script:

            gts = GridTerminalSystem;

            String log = "";
            IMyInventory cA = gts.GetBlockWithName("Small Cargo Container").GetInventory(0);
            IMyInventory cB = gts.GetBlockWithName("Small Cargo Container 2").GetInventory(0);
            IMyInventory cC = gts.GetBlockWithName("Small Cargo Container 3").GetInventory(0);

            List<MyInventoryItem> list = new List<MyInventoryItem>();
            MyInventoryItem item = list[0];
            //MyInventoryItem item = (MyInventoryItem)cA.GetItemAt(0);

            log += "A-B " + cA.CanTransferItemTo(cB, item.Type) +"\n";
            log += "A-C " + cA.CanTransferItemTo(cC, item.Type) +"\n";



I just got a report that this is happening to someone that uses my script. I went to test it and found the same result for the first time in my test that I've ran hundreds of times. I've probably only ran the test with the IsConnectedTo function about 100 times.

I pasted in my test grid. It has 10k of every ore and ingot in a Cargo Container. The container is connected to the rest of the conveyor network via a blacklist sorter that is kept off with nothing blacklisted. I use the sorter as a valve and press a button that turns it on. Normally when I paste in my test grid I will get a list of responses from my script saying the container is not connected to anything, but this time I got no responses. I assume it either cached 'True' that everything is connected (when it is not) or something else changed and it didn't do what it was supposed to do.

Leave a Comment
Attach a file