Swatch Descriptor and Customization Collection

For creating a new Swatch Slot:

Create a BlueprintClass with parent FGFactoryCustomizationDescriptorSwatch Now type fill here ID with the Slot what the swatch should use (Tip: this ID should unique otherwise it will overwrite the other Swatch desc what use this Slot). The Display Name and the Description for that.

Now we want that we see that ingame. We need here a recipe but we need not the FGRecipe we need FGRecipeCustomationRecipe and set the mCustmationDesc to the Swatch Desc. ProduceIn to BuildGun and that's it.

BUT now it will not really work. Because SF know nothing about this Slot.

For adding this Swatch descriptor use a CDO on the BP_CustomizationCollection_Swatches and add them to mCustomizations. Or create a new Collection (parent: FGFactoryCustomizationCollection) with the mCustomizationClass > FGFactoryCustizationDescriptr_Swatch. and add this with CDO to the BuildableSubsystem.

/Game/FactoryGame/Buildable/-Shared/Customization/Swatches/BP_CustomizationCollection_Swatches.BP_CustomizationCollection_Swatches

But that's not all! we need to add a new Colour slot.

So we need a new CDO on the BuildableSubsystem we need to add for the mColorSlotsData a new Colour (or more as one the ID is the Index of this Array... so if you want to use Slot 30 (ID 29) but the Array hols only 19 (Last index 18 because 0 is the first index) colour Slots. Then we need to add 12 Slots (index 29) as long the index is valid.

next, we need also add this Slot to the Gamestate: mBuildingColorSlots_Data also the same.

If we have done this. The Slot is now valid can save and use in the game! The default colour is always black by creating the Slot. I'm not sure why and where the colour is stored. But after changing this colour it always saves and doesn't go back to black.

Short example in C++:

  uint8 ColourIndex = SwatchDesc.GetDefaultObject()->ID;  
  // create new Slots if Slot invalid
  if(!BuildableSubsystem->mColorSlots_Data.IsValidIndex(ColourIndex))  
      // create now Slots
      for(uint8 i = BuildableSubsystem->mColorSlots_Data.Num(); i == ColourIndex; ++i )  
      {  
         FFactoryCustomizationColorSlot NewColourSlot = FFactoryCustomizationColorSlot();
         FGGameState->mBuildingColorSlots_Data.Add(NewColourSlot);  
         BuildableSubsystem->mColorSlots_Data.Add(NewColourSlot);  
         BuildableSubsystem->SetColorSlot_Data(i, NewColourSlot);  // need? it now always work...
         FGGameState->Server_SetBuildingColorDataForSlot(i, NewColourSlot);  // need? it now always work...
         // mark Colours as Dirty for update colours
         BuildableSubsystem->mColorSlotsAreDirty = true;  
      }  

      // Add Desc to Swatch Collection
      if(mDefaultSwatchCollection)  
      {  
         mDefaultSwatchCollection.GetDefaultObject()->mCustomizations.Add(SwatchDesc);  
      }  

Swatch Groups for default swatches

For adding new Swatch groups create a new Swatch Group with C++ or Blueprint (Use UFGSwatchGroup as the parent)

UCLASS()  
class MOD_API UNewSwatchGroup : public UFGSwatchGroup  
{  
   GENERATED_BODY()  
   public:  
   UNewSwatchGroup()  
   {  
      mGroupName = FText::FromString("New Swatch Group");  
   }  
};

then is must add in the AFGGameState to mSwatchGroupDatum

FSwatchGroupData NewGroup;  
NewGroup.Swatch = SwatchDesc_Class;  
NewGroup.SwatchGroup = SwatchGroup_Class;

GameState->mSwatchGroupDatum.Add(NewGroup);
GameState->SetDefaultSwatchForBuildableGroup(SwatchGroup, Swatch);

GameState->SetDefaultSwatchForBuildableGroup(SwatchGroup, Swatch) add them not every time successfully. Why? Idk... that's why I add them directly to mSwatchGroupDatum.

Tip: SetDefaultSwatchForBuildableGroup is also available with Blueprint and mSwatchGroupDatum can make accessible with the Transformers.

Swatch Groups should direct by start of the game created and set. Otherwise all Buildables that use this Swatch group will crash the game if it try to build!


KBFL Customizer Subsystem

I Write a Subsystem in my KBFL mod (open source here) for automic handle and register Swatches. With this Subsystem u need to nothing except to create the swatches and unlock them with a recipe in the schematics.

It read all Swatches and create the default Slots in the Gamestate and Buildable Subsystem.

Warning: if 2 mods use the same ID (between 19-254) it will crash for no overlap each other.


Register swatch groups and set default swatch with KBFL Customizer Subsystem

To register new swatch groups use also the Customizer Subsystem. Create a Subsystem and use this simple BP code:

Or with C++ (for example):

UKBFLCustomizerSubsystem* CustomizerSubsystem = GetWorld()->GetSubsystem<UKBFLCustomizerSubsystem>();
if(CustomizerSubsystem) {
    UKBFLCustomizerSubsystem->SetDefaultToSwatchGroup(SwatchGroup, Swatch)
}

Info

Created: Nov 20, 2021, 11:23:45 AM
Views: 308

Author

Kyri123