### Async Resource Loading with PromiseFuture in Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Loads Unreal Engine assets asynchronously using the Promise pattern, returning a PromiseFuture that resolves when the resource is ready. This prevents frame drops by loading resources in the background. The pattern requires chaining :Then() for the callback and :AutoResume() to start execution. It can load various assets like blueprints, textures, and sounds, as well as UI widget classes. ```lua -- Load a weapon blueprint asynchronously GetAsyncLoadObjectPromiseFuture( PlayerController, -- Outer object (usually PlayerController) "/Game/Weapons/AssaultRifle_BP" -- Full asset path ):Then(function(PromiseFuture) local WeaponBlueprint = PromiseFuture:Get() if WeaponBlueprint then -- Spawn the weapon actor local SpawnTransform = UKismetMathLibrary.MakeTransform( FVector.New(0, 0, 100), FRotator.New(0, 0, 0), FVector.New(1, 1, 1) ) local Weapon = UGameplayStatics.BeginSpawningActorFromBlueprint( PlayerController, WeaponBlueprint, SpawnTransform, false -- bNoCollisionFail ) UGameplayStatics.FinishSpawningActor(Weapon, SpawnTransform) end end):AutoResume() -- Load UI widget class GetAsyncLoadObjectPromiseFuture( PlayerController, "/Game/UI/MainMenu_WBP" ):Then(function(PromiseFuture) local WidgetClass = PromiseFuture:Get() local Widget = UGCWidgetManagerSystem:CreateWidget(WidgetClass) UGCWidgetManagerSystem:ShowWidget(Widget) end):AutoResume() ``` -------------------------------- ### Handle Actor Networking and Replication - Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt This snippet shows how to manage actor networking in Unreal Engine using Lua. It checks for server authority before enabling replication, forcing network updates, and includes examples of how to register for network-related events. ```lua -- Networking if actor:HasAuthority() then TagLogFormatPrint("Running on server") actor:SetReplicates(true) actor:ForceNetUpdate() -- Force immediate replication end ``` -------------------------------- ### Actor Transformation API Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt This section details how to get and set the location and rotation of an actor, as well as how to retrieve its directional vectors. ```APIDOC ## Actor Transformation API ### Description Provides functions for manipulating an actor's position, orientation, and retrieving its spatial vectors. ### Method Various (Lua script calls) ### Endpoint N/A (Object-oriented script functions) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```lua -- Get/Set actor location local Location = actor:K2_GetActorLocation() TagLogFormatPrint("Actor at: %f, %f, %f", Location.X, Location.Y, Location.Z) local SweepResult = {} actor:K2_SetActorLocation( FVector.New(100, 200, 50), -- NewLocation true, -- bSweep (collision detection) SweepResult, -- OUT: collision result false -- bTeleport (ignore collision) ) if SweepResult.bBlockingHit then TagLogFormatPrint("Movement blocked by: %s", tostring(SweepResult.Actor)) end -- Get/Set rotation local Rotation = actor:K2_GetActorRotation() actor:K2_SetActorRotation( FRotator.New(0, 90, 0), -- NewRotation (Pitch, Yaw, Roll) false -- bTeleportPhysics ) -- Get directional vectors local Forward = actor:GetActorForwardVector() local Right = actor:GetActorRightVector() local Up = actor:GetActorUpVector() ``` ### Response #### Success Response (200) N/A (Script execution results) #### Response Example N/A ``` -------------------------------- ### Access and Use AI_Phase Enum in Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Demonstrates how to access read-only AI_Phase enum values in Lua, showing examples of using these constants for state machine logic, function parameters, and logging AI status updates. It also lists all available enum values. ```lua -- Access enum values (read-only) local CurrentPhase = AI_Phase.BornOnSquare -- 0 -- State machine example if character.AIPhase == AI_Phase.BornOnSquare then TagLogFormatPrint("AI spawning on starting platform") elseif character.AIPhase == AI_Phase.TakeInPlane then TagLogFormatPrint("AI inside aircraft") elseif character.AIPhase == AI_Phase.FreeFall then TagLogFormatPrint("AI parachuting") elseif character.AIPhase == AI_Phase.InFighting then TagLogFormatPrint("AI combat mode") elseif character.AIPhase == AI_Phase.NearDeath then TagLogFormatPrint("AI critically injured") elseif character.AIPhase == AI_Phase.Death then TagLogFormatPrint("AI eliminated") elseif character.AIPhase == AI_Phase.Escape then TagLogFormatPrint("AI evacuating") end -- Use in function parameters function SetAIPhase(Character, NewPhase) if NewPhase == AI_Phase.Death then Character:PlayDeathAnimation() end end SetAIPhase(EnemyCharacter, AI_Phase.NearDeath) -- All enum values -- AI_Phase.BornOnSquare = 0 -- AI_Phase.TakeInPlane = 1 -- AI_Phase.FreeFall = 2 -- AI_Phase.InFighting = 3 -- AI_Phase.NearDeath = 4 -- AI_Phase.Death = 5 -- AI_Phase.Escape = 6 ``` -------------------------------- ### Manipulate Actor Transformations and Vectors - Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt This snippet demonstrates how to get and set an actor's location and rotation using Unreal Engine's Lua API. It also shows how to retrieve directional vectors (forward, right, up) and calculate distances to other actors. ```lua -- Get/Set actor location local Location = actor:K2_GetActorLocation() TagLogFormatPrint("Actor at: %f, %f, %f", Location.X, Location.Y, Location.Z) local SweepResult = {} actor:K2_SetActorLocation( FVector.New(100, 200, 50), -- NewLocation true, -- bSweep (collision detection) SweepResult, -- OUT: collision result false -- bTeleport (ignore collision) ) if SweepResult.bBlockingHit then TagLogFormatPrint("Movement blocked by: %s", tostring(SweepResult.Actor)) end -- Get/Set rotation local Rotation = actor:K2_GetActorRotation() actor:K2_SetActorRotation( FRotator.New(0, 90, 0), -- NewRotation (Pitch, Yaw, Roll) false -- bTeleportPhysics ) -- Get directional vectors local Forward = actor:GetActorForwardVector() local Right = actor:GetActorRightVector() local Up = actor:GetActorUpVector() -- Calculate distance to another actor local Distance = actor:GetDistanceTo(TargetActor) local HorizontalDistance = actor:GetHorizontalDistanceTo(TargetActor) TagLogFormatPrint("Distance: 3D=%f, 2D=%f", Distance, HorizontalDistance) ``` -------------------------------- ### Spawn Actor from Blueprint and Class with UGameplayStatics (Lua) Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Demonstrates spawning actors from both blueprint classes and generic classes using UGameplayStatics. Includes deferred spawning with UGameplayStatics.BeginSpawningActorFromBlueprint and UGameplayStatics.BeginSpawningActorFromClass, followed by UGameplayStatics.FinishSpawningActor to complete initialization. Also shows how to retrieve player controllers and game mode/state. ```lua -- Spawn actor from blueprint with deferred construction local SpawnTransform = UKismetMathLibrary.MakeTransform( FVector.New(500, 1000, 100), -- Location FRotator.New(0, 90, 0), -- Rotation FVector.New(1, 1, 1) -- Scale ) local NewActor = UGameplayStatics.BeginSpawningActorFromBlueprint( PlayerController, -- WorldContextObject ActorBlueprint, -- Blueprint class SpawnTransform, -- Transform true -- bNoCollisionFail (spawn even if overlapping) ) if NewActor then -- Set properties before construction NewActor.Health = 100 NewActor.TeamID = 1 -- Finish spawning (calls BeginPlay) UGameplayStatics.FinishSpawningActor(NewActor, SpawnTransform) end -- Spawn actor from class local EnemyClass = LoadClass("Blueprint'/Game/Characters/Enemy_BP.Enemy_BP_C'") local Enemy = UGameplayStatics.BeginSpawningActorFromClass( PlayerController, EnemyClass, SpawnTransform, false -- bNoCollisionFail ) UGameplayStatics.FinishSpawningActor(Enemy, SpawnTransform) -- Get player controller by index local Player0 = UGameplayStatics.GetPlayerController(PlayerController, 0) local Player1 = UGameplayStatics.GetPlayerController(PlayerController, 1) -- Get game mode (Server only) if actor:HasAuthority() then local GameMode = UGameplayStatics.GetGameMode(PlayerController) TagLogFormatPrint("Game mode: %s", tostring(GameMode)) end -- Get game state (Both) local GameState = UGameplayStatics.GetGameState(PlayerController) -- Spawn generic object local NewObject = UGameplayStatics.SpawnObject( ObjectClass, PlayerController -- Outer (can be nil) ) ``` -------------------------------- ### Manage UI Widgets with UGCWidgetManagerSystem (Lua) Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Provides functionality for managing UI widgets, including synchronous and asynchronous creation, adding to specific UI slots with Z-order and anchoring, showing, hiding, removing, and destroying widgets. It also allows checking widget visibility and retrieving all widgets within a slot. ```lua -- Create widget synchronously local WidgetClass = LoadClass("WidgetBlueprint'/Game/UI/MainMenu.MainMenu_C'") local MainMenu = UGCWidgetManagerSystem:CreateWidget(WidgetClass) -- Add to UI slot with anchoring UGCWidgetManagerSystem:AddToSlot( MainMenu, "UI.UISlot.MainUISlot_High", -- Slot name (High = top layer) 10, -- ZOrder (higher = front) { Anchors = { Minimum = Vector2D.New(0, 0), -- Top-left anchor Maximum = Vector2D.New(1, 1) -- Bottom-right anchor (fullscreen) }, Alignment = Vector2D.New(0.5, 0.5), -- Center alignment Offsets = { Left = 0, Top = 0, Right = 0, Bottom = 0 } } ) -- Show widget UGCWidgetManagerSystem:ShowWidget(MainMenu) -- Create widget asynchronously UGCWidgetManagerSystem:CreateWidgetAsync( "/Game/UI/HUD_WBP", -- Widget path or FSoftObjectPath function(Widget) if Widget then UGCWidgetManagerSystem:AddToSlot( Widget, "UI.UISlot.MainUISlot_Low", 0, { Anchors = { Minimum = Vector2D.New(0, 0), Maximum = Vector2D.New(1, 1) } } ) UGCWidgetManagerSystem:ShowWidget(Widget) end end ) -- Hide widget (keeps in memory) UGCWidgetManagerSystem:HideWidget(MainMenu) -- Remove from slot (unparents but keeps alive) UGCWidgetManagerSystem:RemoveFromSlot(MainMenu) -- Destroy widget (removes from memory) UGCWidgetManagerSystem:DestroyWidget(MainMenu) -- Check if widget is showing local IsShowing = UGCWidgetManagerSystem:IsWidgetShowing(MainMenu) -- Get all widgets in a slot local SlotWidgets = UGCWidgetManagerSystem:GetWidgetsInSlot("UI.UISlot.MainUISlot_High") for i, Widget in ipairs(SlotWidgets) do TagLogFormatPrint("Widget %d: %s", i, tostring(Widget)) end ``` -------------------------------- ### Actor Networking and Replication API Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt API for managing actor replication and forcing network updates, primarily for server-side operations. ```APIDOC ## Actor Networking and Replication API ### Description Manages an actor's network replication status and allows for forcing immediate network updates. Requires server authority. ### Method Various (Lua script calls, server-side) ### Endpoint N/A (Object-oriented script functions) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```lua -- Networking if actor:HasAuthority() then TagLogFormatPrint("Running on server") actor:SetReplicates(true) actor:ForceNetUpdate() -- Force immediate replication end ``` ### Response #### Success Response (200) N/A (Script execution results) #### Response Example N/A ``` -------------------------------- ### E-Commerce Commodity Operations in Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Manages in-game commerce operations including product purchases, inventory queries, and purchase history. Supports both client-initiated real currency purchases and server-side custom currency purchases. It includes delegates for monitoring purchase results and inventory updates. Functions require appropriate controllers or player keys for execution. ```lua local CanBuy = CommodityOperationManager:CanAfford( 10001, -- ProductID 2, -- Quantity PlayerController ) if CanBuy then local ProductData = CommodityOperationManager:GetProductData(10001) local PromiseFuture = CommodityOperationManager:BuyProduct( 10001, -- ProductID 2, -- Num ProductData.Price * 2, -- CurrentPrice (for validation) false -- bCheckPrivilege ) if PromiseFuture then PromiseFuture:Then(function(result) TagLogFormatPrint("Purchase UI completed") end):AutoResume() end end CommodityOperationManager:ServerBuyProduct( PlayerKey, -- Player's unique key 10002, -- ProductID 1, -- Num 500, -- CurrentPrice (in-game currency) true -- bCheckPrivilege ) CommodityOperationManager.BuyProductResultDelegate:Register(function(Result) if Result.Success then TagLogFormatPrint("Purchase successful: Product %d", Result.ProductID) else TagLogFormatPrint("Purchase failed: %s", Result.ErrorMessage) end end) local PurchasedTimes = CommodityOperationManager:GetPurchasedTimes( 10001, PlayerController ) TagLogFormatPrint("Player purchased this product %d times", PurchasedTimes) local LimitProducts = CommodityOperationManager:GetAllLimitPurchasedProducts(PlayerController) for i, Product in ipairs(LimitProducts) do TagLogFormatPrint("Limited product %d: purchased %d times", Product.ID, Product.Times) end ``` -------------------------------- ### Formatted Logging System in Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt A flexible logging function that supports three modes: simple string output, formatted string with parameters (similar to printf), and full control with category and verbosity level. It is available on both server and client. The default category is 'LogTagLog' and the default level is 'Log'. ```lua -- Mode 1: Simple string log TagLogFormatPrint("Player spawned successfully") -- Mode 2: Formatted string with parameters local PlayerName = "Alice" local Health = 100 local Position = FVector.New(120.5, 340.2, 50.0) TagLogFormatPrint( "Player %s spawned at (%f, %f, %f) with health %d", PlayerName, Position.X, Position.Y, Position.Z, Health ) -- Mode 3: Full control with category and verbosity TagLogFormatPrint( "GameplaySystem", -- Category name ELogVerbosity.Warning, -- Verbosity level (Log, Warning, Error) "Weapon %s ammo low: %d/%d remaining", WeaponName, CurrentAmmo, MaxAmmo ) -- Error logging TagLogFormatPrint( "NetworkSystem", ELogVerbosity.Error, "Failed to replicate actor %s to client %d", tostring(Actor), ClientID ) ``` -------------------------------- ### Manage Actor Attachments - Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt This Lua code illustrates how to attach one actor to another, specifying socket names and attachment rules for location, rotation, and scale. It also includes the process for detaching an actor. ```lua -- Attach to another actor actor:K2_AttachToActor( ParentActor, -- Parent "WeaponSocket", -- SocketName EAttachmentRule.SnapToTarget, -- LocationRule EAttachmentRule.SnapToTarget, -- RotationRule EAttachmentRule.KeepWorld, -- ScaleRule false -- bWeldSimulatedBodies ) -- Detach actor:DetachFromActor( EDetachmentRule.KeepWorld, -- LocationRule EDetachmentRule.KeepWorld, -- RotationRule EDetachmentRule.KeepWorld -- ScaleRule ) ``` -------------------------------- ### Actor Collision and Damage Delegates API Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Registering callbacks for collision events such as overlaps, hits, and damage taken. ```APIDOC ## Actor Collision and Damage Delegates API ### Description Allows for registering callback functions to handle various collision and damage events related to an actor. ### Method Various (Lua script calls) ### Endpoint N/A (Object-oriented script functions) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```lua -- Register collision delegates actor.OnActorBeginOverlap:Register(function(OverlappedActor, OtherActor) TagLogFormatPrint("Overlap began with: %s", tostring(OtherActor)) end) actor.OnActorEndOverlap:Register(function(OverlappedActor, OtherActor) TagLogFormatPrint("Overlap ended") end) actor.OnActorHit:Register(function(SelfActor, OtherActor, NormalImpulse, Hit) TagLogFormatPrint("Hit at: %f, %f, %f", Hit.Location.X, Hit.Location.Y, Hit.Location.Z) end) actor.OnTakeAnyDamage:Register(function(DamagedActor, Damage, DamageType, InstigatedBy, DamageCauser) TagLogFormatPrint("Took %f damage from %s", Damage, tostring(DamageCauser)) end) ``` ### Response #### Success Response (200) N/A (Callback execution) #### Response Example N/A ``` -------------------------------- ### Actor Lifecycle Management API Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Functionality for destroying actors, restricted to server-side execution. ```APIDOC ## Actor Lifecycle Management API ### Description Provides the capability to destroy an actor. This function is restricted to server-side execution. ### Method Various (Lua script calls, server-side) ### Endpoint N/A (Object-oriented script functions) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```lua -- Destroy actor (Server only) if actor:HasAuthority() then actor:K2_DestroyActor() end ``` ### Response #### Success Response (200) N/A (Actor destruction) #### Response Example N/A ``` -------------------------------- ### Register Collision and Damage Event Delegates - Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt This Lua code demonstrates how to register delegate functions for various actor collision and damage events. It covers `OnActorBeginOverlap`, `OnActorEndOverlap`, `OnActorHit`, and `OnTakeAnyDamage`, allowing for custom event handling. ```lua -- Register collision delegates actor.OnActorBeginOverlap:Register(function(OverlappedActor, OtherActor) TagLogFormatPrint("Overlap began with: %s", tostring(OtherActor)) end) actor.OnActorEndOverlap:Register(function(OverlappedActor, OtherActor) TagLogFormatPrint("Overlap ended") end) actor.OnActorHit:Register(function(SelfActor, OtherActor, NormalImpulse, Hit) TagLogFormatPrint("Hit at: %f, %f, %f", Hit.Location.X, Hit.Location.Y, Hit.Location.Z) end) actor.OnTakeAnyDamage:Register(function(DamagedActor, Damage, DamageType, InstigatedBy, DamageCauser) TagLogFormatPrint("Took %f damage from %s", Damage, tostring(DamageCauser)) end) ``` -------------------------------- ### Actor Relationship and Distance API Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Functions for calculating distances between actors and attaching/detaching actors to each other. ```APIDOC ## Actor Relationship and Distance API ### Description Enables calculation of distances between actors and managing parent-child attachment relationships. ### Method Various (Lua script calls) ### Endpoint N/A (Object-oriented script functions) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```lua -- Calculate distance to another actor local Distance = actor:GetDistanceTo(TargetActor) local HorizontalDistance = actor:GetHorizontalDistanceTo(TargetActor) TagLogFormatPrint("Distance: 3D=%f, 2D=%f", Distance, HorizontalDistance) -- Attach to another actor actor:K2_AttachToActor( ParentActor, -- Parent "WeaponSocket", -- SocketName EAttachmentRule.SnapToTarget, -- LocationRule EAttachmentRule.SnapToTarget, -- RotationRule EAttachmentRule.KeepWorld, -- ScaleRule false -- bWeldSimulatedBodies ) -- Detach actor:DetachFromActor( EDetachmentRule.KeepWorld, -- LocationRule EDetachmentRule.KeepWorld, -- RotationRule EDetachmentRule.KeepWorld -- ScaleRule ) ``` ### Response #### Success Response (200) N/A (Script execution results) #### Response Example N/A ``` -------------------------------- ### Character Control Event Overrides in Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt Provides overridable events for gameplay systems like weapons, damage, and death, along with callable functions for character manipulation. Events are triggered automatically by the engine, and server-only functions require authority checks. This snippet demonstrates overriding weapon fire, bullet hit, damage calculation, and player death events, as well as a server-only teleport function. ```lua local MyCharacter = {} function MyCharacter:UGC_WeaponShootBulletEvent(ShootWeapon, Bullet) TagLogFormatPrint("Weapon fired: %s", tostring(ShootWeapon)) end function MyCharacter:UGC_WeaponBulletHitEvent(ShootWeapon, Bullet, HitInfo) TagLogFormatPrint("Hit location: (%f, %f, %f)", HitInfo.Location.X, HitInfo.Location.Y, HitInfo.Location.Z ) end function MyCharacter:UGC_TakeDamageOverrideEvent(Damage, DamageType, EventInstigator, DamageCauser, Hit) local Armor = self:GetArmorValue() local FinalDamage = Damage * (1.0 - Armor / 100.0) TagLogFormatPrint("Original damage: %f, Final damage: %f", Damage, FinalDamage) return FinalDamage end function MyCharacter:UGC_PlayerDeadEvent(Killer, DamageType) if Killer then TagLogFormatPrint("Player killed by: %s", tostring(Killer)) else TagLogFormatPrint("Player died (no killer)") end end if self:HasAuthority() then self:DSTeleportToLocationOrRotation( FVector.New(1000, 2000, 300), -- location FRotator.New(0, 180, 0), -- rotation true, -- setLoc true, -- setRot true, -- ResetVelocity true -- bRecordTeleportInfo ) end local CurrentHealth = self:GetCurrentHealth() local MaxHealth = self:GetMaxHealth() TagLogFormatPrint("Health: %f/%f", CurrentHealth, MaxHealth) ``` -------------------------------- ### Destroy Actor - Lua Source: https://context7.com/legendxcheng/sweetstart_oasis/llms.txt This Lua snippet shows how to destroy an actor in Unreal Engine. It includes a check for server authority, as actor destruction is typically a server-only operation. ```lua -- Destroy actor (Server only) if actor:HasAuthority() then actor:K2_DestroyActor() end ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.