4. Auto Insertion & Extraction - Theuntextured/AsyncConveyorPlugin GitHub Wiki

Insertion

In the Conveyor Component, there exists a property in the Conveyor section called Auto Insert:

image

In order to automatically insert, you will need to set this to WithConditionCheck or Always.

  • None means that automatic insertion will never occur on this component.
  • WithConditionCheck means that an insertion will only occur if the connection (conveyor segment) to insert in leads to another connection(s).
  • Always will always insert.

In the conveyor manager, you will also need to override a function. This function is named Handle Auto Insertion. It has a vector and a conveyor component object reference as inputs and an Item struct and a bool as outputs. This function should determine if and what item should be inserted.

  • Location (in vector) is the location to insert into.
  • Component (in Conveyor Component Object Reference) is the component that is responsible for the automatic insertion.
  • Item To Insert (out Item) is the item to insert.
  • Return Value (out bool) is whether or not to insert the item.

Here is an example of an implementation of the function:

image

The first section casts the owner of the component to an inserter actor; if the cast was successful, insert an item (defined in a variable inside the inserter).

The second section casts the owner to a container actor. If an item is in its inventory, it will return the item and the item will be inserted, otherwise, return false.

(ADVANCED) In addition to this, the manager has a bool property called Auto Insertion on Any Thread. Enabling this will allow insertions and insertion checks to occur off the game thread and in a ParallelFor. If your Handle Auto Insertion function is completely thread safe, then you can enable this setting. If not or you are unsure, then you should keep it false.

Extraction

In the Conveyor Component, find the property in the Conveyor section called Belt End Behaviour:

image

In order to automatically extract, you will need to set this to Auto Extract. The Drop option was discussed in the Conveyor Component section. On the other hand, None will obviously not extract nor drop.

In the conveyor manager, you will also need to override a function. This function is named Handle Auto Extraction. It has an item struct, a vector and a conveyor component object reference as inputs and a bool as output. This function should determine if and what item should be inserted.

  • Location (in vector) is the location to extract from.
  • Component (in Conveyor Component Object Reference) is the component that is responsible for the automatic extraction.
  • Item (out Item) is the item to extract.
  • Return Value (out bool) is whether or not to extract the item.

Here is an example of an implementation of the function:

image

The first section checks if the owner of the component is an extractor, if it is, then always extract.

The second section casts the owner of the component to a container (same one as in the insertion section), and checks if there is space in the inventory. If there is, then extract the item and add the item to the inventory.

(ADVANCED) In addition to this, the manager has a bool property called Auto Extraction on Any Thread. Enabling this will allow extractions and extraction checks to occur off the game thread and in a ParallelFor (while processing items). If your Handle Auto Extraction function is completely thread safe, then you can enable this setting. If not or you are unsure, then you should keep it false.