Class ProductPopulator
Creates product instances and adds them to storage for mod-owned setup flows.
public static class ProductPopulator
- Inheritance
-
ProductPopulator
- Inherited Members
Remarks
Discovery-based helpers read products discovered in the active save. ID-based helpers resolve registered definitions through the item registry, while direct-creation helpers use the supplied definition. These APIs do not register products or stock shops. Use explicit custom-product lifecycle APIs before calling them for mod-owned definitions.
Methods
CreatePackagedProduct(ProductDefinition, PackagingDefinition, int)
Creates a standard-quality packaged product instance.
public static ProductInstance? CreatePackagedProduct(ProductDefinition productDef, PackagingDefinition packaging, int quantity)
Parameters
productDefProductDefinitionThe product definition.
packagingPackagingDefinitionThe packaging definition.
quantityintThe quantity of the product.
Returns
- ProductInstance
A new product instance, or null when native packaging conversion or construction fails.
GetAllProductDefinitions()
Gets product definitions discovered in the active save.
public static List<ProductDefinition> GetAllProductDefinitions()
Returns
- List<ProductDefinition>
A new list of discovered product definitions. It is empty when the save has discovered none.
GetCocaineDefinitions()
Gets discovered cocaine-family product definitions.
public static List<CocaineDefinition> GetCocaineDefinitions()
Returns
- List<CocaineDefinition>
A list of cocaine product definitions.
GetMethDefinitions()
Gets discovered methamphetamine-family product definitions.
public static List<MethDefinition> GetMethDefinitions()
Returns
- List<MethDefinition>
A list of meth product definitions.
GetPackaging(string)
Resolves a native packaging definition by its item ID.
public static PackagingDefinition? GetPackaging(string packagingId)
Parameters
packagingIdstringThe ID of the packaging (e.g., "baggie", "jar", "brick").
Returns
- PackagingDefinition
The live packaging definition, or null when the item is absent or not packaging.
GetShroomDefinitions()
Gets discovered shroom-family product definitions.
public static List<ShroomDefinition> GetShroomDefinitions()
Returns
- List<ShroomDefinition>
A list of shroom product definitions.
GetWeedDefinitions()
Gets discovered marijuana-family product definitions.
public static List<WeedDefinition> GetWeedDefinitions()
Returns
- List<WeedDefinition>
A list of weed product definitions.
PopulateFromGameObject(GameObject, string, int)
Finds a storage entity on a game object or one of its children, then fills it with packaged products.
public static int PopulateFromGameObject(GameObject gameObject, string packagingId, int quantityPerItem = 1)
Parameters
gameObjectGameObjectThe GameObject with a StorageEntity component.
packagingIdstringThe ID of the packaging to use (e.g., "baggie", "jar", "brick").
quantityPerItemintThe quantity of each product item.
Returns
- int
The number of stacks added, or
-1when no storage entity is found.
PopulateWithPackagedProducts(StorageInstance, string, int)
Fills available storage slots with packaged discovered products.
public static int PopulateWithPackagedProducts(StorageInstance storage, string packagingId, int quantityPerItem = 1)
Parameters
storageStorageInstanceThe storage instance to populate.
packagingIdstringThe ID of the packaging to use (e.g., "baggie", "jar", "brick").
quantityPerItemintThe quantity of each product item.
Returns
- int
The number of stacks added before storage fills, a product cannot fit, or setup fails.
PopulateWithSpecificPackagedProducts(StorageInstance, List<string>, string, int)
Adds one packaged stack for each supplied product ID that resolves and fits.
public static int PopulateWithSpecificPackagedProducts(StorageInstance storage, List<string> productIds, string packagingId, int quantityPerProduct = 1)
Parameters
storageStorageInstanceThe storage instance to populate.
productIdsList<string>Product IDs to resolve through the item registry.
packagingIdstringThe ID of the packaging to use (e.g., "baggie", "jar", "brick").
quantityPerProductintQuantity of each product to add (default 1).
Returns
- int
The number of stacks added. Unknown IDs and stacks that do not fit are skipped.
PopulateWithSpecificProducts(StorageInstance, List<string>, int)
Adds one unpackaged stack for each supplied product ID that resolves and fits.
public static int PopulateWithSpecificProducts(StorageInstance storage, List<string> productIds, int quantityPerProduct = 1)
Parameters
storageStorageInstanceThe storage instance to populate.
productIdsList<string>Product IDs to resolve through the item registry.
quantityPerProductintQuantity of each product to add (default 1).
Returns
- int
The number of stacks added. Unknown IDs and stacks that do not fit are skipped.
PopulateWithUnpackagedProducts(StorageInstance, int)
Fills available storage slots with unpackaged discovered products.
public static int PopulateWithUnpackagedProducts(StorageInstance storage, int quantityPerItem = 1)
Parameters
storageStorageInstanceThe storage instance to populate.
quantityPerItemintThe quantity of each product item.
Returns
- int
The number of stacks added before storage fills, a product cannot fit, or setup fails.
PopulateWithWeedProducts(StorageInstance)
Fills available storage slots with discovered products in native jar packaging.
public static int PopulateWithWeedProducts(StorageInstance storage)
Parameters
storageStorageInstanceThe storage instance to populate.
Returns
- int
The number of stacks successfully added.