GridTerminalSystem.GetBlocksOfType<B>(List<A>) does not populate the list, even when B extends A

Reika Kalseki shared this bug 4 years ago
Outdated

This comes up primarily in the programmable block; despite the fact that a List of objects of type A should accept any object of type B where B extends A ('class B : A' in C# syntax), and neither IDEs nor the ingame checker detect errors on that code, the list remains empty and thus useless.


Example code:

List<IMyTerminalBlock> li = new List<IMyTerminalBlock>();

GridTerminalSystem.GetBlocksOfType<IMyReactor>(li);

GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(li);


Expected result: A list of all batteries AND reactors on the ship.

Actual result: Empty list.

Replies (2)

photo
1

I think that `GetBlocksOfType` will always clear the list, before filling it.

Try to echo how many elements the list contain, after each method call. Something like this, to examine what happens:

var li = new List<IMyTerminalBlock>();
Echo("a) li.Count=" + li.Count);
GridTerminalSystem.GetBlocksOfType<IMyReactor>(li);
Echo("b) li.Count=" + li.Count);
GridTerminalSystem.GetBlocksOfType<IMyBatteryBlock>(li);
Echo("c) li.Count=" + li.Count);

BTW: Also make sure that you have ownership of the corresponding reactor- and battery-blocks.

photo
1

This is not helpful; That would not result in an empty list.

photo
1

It would result in an empty list if there are no batteries or the PB can't access the batteries, most common issue being PB is not owned while batteries are owned.


As for having a list with 2 types, you either have to use multiple lists or give the method a null list and add to your single list using the 2nd arg.

photo
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

Leave a Comment
 
Attach a file