Cookbook
|
You have found a hidden docs page! This page is still a work in progress. If you have any feedback, please let us know in the Discord. |
Collection of assorted code snippets and useful approaches.
TActorIterator
Faster than GetAllActorsOfClass and GetTypedBuildable
for (TActorIterator<YourBuildableClass> It(GetWorld()); It; ++It)
{
YourBuildableClass* Buildable = *It;
....
}
SetTimerForNextTick
FName Tag;
if (ResourceRouletteCompatibilityManager::IsCompatibilityClass(SpawnedActor, Tag))
{
World->GetTimerManager().SetTimerForNextTick([World, SpawnedActor, Tag]()
{
ResourceRouletteCompatibilityManager::TagActorAndMesh(SpawnedActor, Tag);
});
}
Custom Attachment Points
const TSubclassOf<UFGAttachmentPointType> Type = point.Type;
const TSubclassOf<UFGAttachmentPointType> SnappedType = targetPoint.Type;
UFGAttachmentPointType* LocalObject = Type.GetDefaultObject();
const UFGAttachmentPointType* RemoteObject = SnappedType.GetDefaultObject();
for (auto SnapType : LocalObject->mAllowedAttachmentPointSnapTypes) {
if(RemoteObject->IsA(SnapType)) {
return true;
}
}
return false;
Check if Main Menu
Keep in mind that 99.99% of the time your logic should not require you to do this, use something like a game world mod module instead.
if (AFGGameMode* GameMode = World->GetAuthGameMode<AFGGameMode>()) {
return GameMode->IsMainMenuGameMode();
}
return false;
Lightweight Buildable Ref Struct Data Access
const FRuntimeBuildableInstanceData* RuntimeData = Ref.ResolveBuildableInstanceData();
const FBuildableBeamLightweightData* beamData = RuntimeData->TypeSpecificData.GetValuePtr<FBuildableBeamLightweightData>();
float length = beamData->BeamLength;
return length;
Finding and Modifying a Config Property via Cā+ā+
Possibly move this to the Configuration docs page? Is it possible to do this via the generated config structs instead?
Example from InfiniteNudge.
UConfigManager* ConfigManager = GetWorld()->GetGameInstance()->GetSubsystem<UConfigManager>();
auto root = ConfigManager->GetConfigurationRootSection({ "InfiniteNudge", "" });
CastChecked<UConfigPropertyBool>(root->SectionProperties.FindChecked("ShowScrollModeGizmo"))->Value = UInfiniteGizmo::Toggle();
root->MarkDirty();