Exploration of new usage relative to personal in ActionRoguelike source code

Migrating from Zhihu to CSDN Original address: Furnace Shuke
Source code address: ActionRoguelike Source Github
course address: Professional Game Development in C++ and Unreal Engine

  • Generation parameter configuration in SpawnActor in C++ source code: FActorSpawnParameter in SpawnActor comes with some additional control parameters during generation, which are used to finely control the generated Actor:
  1. Name: The name of the generated Actor. If no parameters are passed, it will be automatically named as[Class]_[Number]
  2. Template: Use the existing Actor as a template to generate a new Actor, and the generated Actor will use the attribute value of this Actor instance to assign itself, which is very useful for copying the existing Actor in the world scene (equivalent to the shadow clone )
  3. Owner: Generate the owner of the Actor, can be empty
  4. Instigator: source of damage control (usually refers to the Actor's Controller or the Actor's Owner), can be empty
  5. OverrideLevel: The current Level, can be empty, when it is empty, this parameter has its own set of search rules
  6. SpawnCollisionHandlingOverride: In the case of collision penetration, the available spawn strategies are: default rule; always spawn; adjust spawn position and always spawn; adjust spawn position but not spawn if there is a collision; if there is a collision not generated
  7. ESpawnActorNameMode: When spawning Actors, the naming process rules (especially naming conflicts): fatal break, error and return empty, return empty when not available
  • ensuremacro with IsValid():
  1. ensure series macro functions:
  • The ensure series macro functions are the re-encapsulation of the UE_ENSURE_IMPL macro, which are used for message printing control of different degrees of fineness
  • UE_ENSURE_IMPL can be used to detect non-fatal runtime errors. When an error occurs, a crash record will be printed and a record will be sent to the flashback server (this record contains the stack information of the crash) without flashback
  • The first parameter of UE_ENSURE_IMPL is the parameter passing control of the lambda function, always is used to control whether you handle every error that may occur by yourself, ... is additional information when printing the error log
  • ensure can be embedded in the judgment statement, especially in those places where you need to obtain and provide crash records (from this perspective, ensure is very useful to obtain real-time records at runtime).
  • UE_ENSURE_IMPL has a cross-platform nature and can work well on different operating platforms, which is very friendly for platform debugging
  • ensure has four encapsulation macros for UE_ENSURE_IMPL, namely: ensure, ensureMsgf, ensureAlways, ensureAlwaysMsgf, the difference between them mainly lies in the handling of errors and the control of content parameters when printing error messages
  • UE_ENSURE_IMPL passed in an expression
  1. IsValid()function:
  • IsValid is dependent on the Object inheritance system (it is a function in Object), in other words, objects that do not inherit from Object cannot use IsValid
  • IsValid only judges whether the pointer is empty and whether it is in the recycling of GC, that is to say, IsValid cannot handle status judgments other than these two cases
  • IsValid is passed in a constant pointer to the object
  • Thoughts on the SAction module
  1. SAction inherits from UObject, and SAction has attribute synchronization, which needs to implement the ReplicateSubobjects method in the SActionComponent holding SAction to complete the synchronization chain of ActorChannel
  2. There is no ReplicateSubobjects method in UObject. Similarly, when encountering Object synchronization, you need to manually add it to ReplicateSubobjects
  3. Typical applications: UGameplayAbility synchronization in UAbilitySystemComponent, UGameplayTask synchronization in UGameTasksComponent
  4. There are four core functions in SAction: CanStart, StartAction, StopAction, and IsRunning. These four functions are blueprints that can be realized; the synchronization data is the Action start time, the Action holder USActionComponent pointer, and the Action running status (whether it is running, Instigator )
  5. The core methods in USActionComponent: AddAction, RemoveAction, GetAction, ServerStartAction, ServerStopAction, StartActionByName and StopActionByName, manage the generation, operation, stop, and recycling of SAction
  6. SAction and SActionComponent are similar to the factory mode, SAction is responsible for specific Action logic, and SActionComponent is responsible for generating and managing SAction
  7. USAction_ProjectileAttack inherits from SAction, which is a specific bullet attack application scheme of SAction. The specific damage logic is in AttackDelay_Elapsed, and this function call exists in the timer on the server side.
  8. USActionEffect inherits from SAction, which is a way to implement Buff effects (persistence for a period of time, persistent Buff, etc.). It is worth mentioning that there is a method GetServerWorldTimeSeconds() for obtaining server-side world time in AGameStateBase, and the calculation of world time In terms of uniformity, it is best to calculate uniformly according to server-side time
  9. Personally, this module feels like a simplified version of GAS, which is used to complete the logical update and display of attributes, buffs, etc.
  • AI locking strategy in SAICharacter
  1. SAICharacter adopts the multicast method, and registers FSeePawnDelegate and FOnAttributeChanged from the attribute management module of USAttributeComponent and the perception module of PawnSensingComponent. Another commonly used multicast in PawnSensingComponent is FHearNoiseDelegate OnHearNoise, which is used to perform some operations when hearing noise
  2. Monster spawn strategy in SGameMode
  • There is an environment query member attribute in GameMode SpawnBotQuery(UEnvQuery), the query strategy of this member attribute in the blueprint is: distance from all players and path accessibility
  • When the game starts, UEnvQueryManager::RunEQSQueryget it through the query function
  • UEnvQueryInstanceBlueprintWrapperinstance, and then bind the multicast delegate GetOnQueryFinishedEvent()to obtain the generated coordinates(QueryInstance->GetResultsAsLocation())
  • According to the coordinate points and the configuration of generating monsters, monsters are generated at random positions (in actual project development, there are strict rules for generating monsters, not necessarily automatic random generation, such as generating monster volume, etc., are all strategically configured and generated Way)
  • Serialization and deserialization strategies:
  1. Two kinds of data storage are reserved in SaveGame: 1. Player data (score, generated position, rotation, etc.); 2. Actor storage in the world scene, the core data is a type of data TArray<uint8>storage
  2. The core method of writing and loading data is implemented in SaveGameSubsystem. These two methods serialize and deserialize the core saved data in SaveGame
  3. The deserialization of player data is mainly aimed at the deserialization of PlayerState data. The method is implemented in PlayerState. SavePlayerStateThese LoadPlayerStatetwo methods are similar to the method in the SaveGame subsystem, but the current two methods are aimed at It is the current player data, which is more common in the player's online and offline data storage
  4. SaveGameSettingsThe serialization configuration is retained in SaveSlotName, and the deserialized data is read through this property.
  • Framework strategies for interactable objects in the world:
  1. All interactive objects implement the interface ISGameplayInterface, which mainly declares three core methods:
  • OnActorLoaded: Called after the Actor is reloaded
  • GetInteractText: Get the interaction description text
  • Interact: Implementation of interaction logic
    These three methods complete the response methods of all interactive objects. The SInteractionComponent component realizes the search of interactive Actors and the call of interactive
    interface methods. The Interact method call of the specific interactive objectFindBestInteractableServerInteract

Guess you like

Origin blog.csdn.net/u011047958/article/details/125265422