--------------------------------------------------------------------------------------------------------------------------
| 119 | |
| 120 | //-------------------------------------------------------------------------------------------------------------------------- |
| 121 | void UCogSampleProjectileComponent::Activate(bool bReset) |
| 122 | { |
| 123 | COG_LOG_OBJECT(LogCogProjectile, ELogVerbosity::Verbose, Creator.Get(), TEXT("Projectile:%s | Role:%s | bReset:%d"), *GetNameSafe(GetOwner()), *GetRoleName(), bReset); |
| 124 | |
| 125 | //------------------------------------------------------------------------------------------------ |
| 126 | // Save the spawn location and rotation and get them replicated because, we want remote clients |
| 127 | // to tick projectiles on their own, and be synced with the server. To do so they need to |
| 128 | // recompute (to catchup) the projectile movement from its initial location, rotation and velocity. |
| 129 | // If we don't reposition the remote client projectile at its initial values, we get some offset |
| 130 | // because the server doesn't necessarly replicates the location and rotation of the projectile |
| 131 | // at its spawn frame. |
| 132 | //------------------------------------------------------------------------------------------------ |
| 133 | if (GetOwner()->GetLocalRole() == ROLE_Authority) |
| 134 | { |
| 135 | COMPARE_ASSIGN_AND_MARK_PROPERTY_DIRTY(UCogSampleProjectileComponent, ServerSpawnLocation, GetOwner()->GetActorLocation(), this); |
| 136 | COMPARE_ASSIGN_AND_MARK_PROPERTY_DIRTY(UCogSampleProjectileComponent, ServerSpawnRotation, GetOwner()->GetActorRotation(), this); |
| 137 | COMPARE_ASSIGN_AND_MARK_PROPERTY_DIRTY(UCogSampleProjectileComponent, ServerSpawnVelocity, Velocity, this); |
| 138 | } |
| 139 | else |
| 140 | { |
| 141 | GetOwner()->SetActorLocationAndRotation(ServerSpawnLocation, ServerSpawnRotation); |
| 142 | Velocity = ServerSpawnVelocity; |
| 143 | } |
| 144 | |
| 145 | #if ENABLE_COG && !NO_LOGGING |
| 146 | DrawDebugCurrentState(FColor::Green); |
| 147 | if (FCogDebugLog::IsLogCategoryActive(LogCogProjectile)) |
| 148 | { |
| 149 | LastDebugLocation = GetOwner()->GetActorLocation(); |
| 150 | } |
| 151 | #endif //ENABLE_COG && !NO_LOGGING |
| 152 | |
| 153 | //-------------------------------------------------------------------------- |
| 154 | // Catchup after settings LastDebugLocation because Tick will be triggered |
| 155 | // by Catchup and LastDebugLocation is used in Tick debug draw. |
| 156 | //-------------------------------------------------------------------------- |
| 157 | if (GetOwner()->GetLocalRole() != ROLE_Authority) |
| 158 | { |
| 159 | if (LocalPlayerController != nullptr) |
| 160 | { |
| 161 | Catchup(LocalPlayerController->GetClientLag()); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | Super::Activate(bReset); |
| 166 | } |
| 167 | |
| 168 | //-------------------------------------------------------------------------------------------------------------------------- |
| 169 | void UCogSampleProjectileComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) |
nothing calls this directly
no test coverage detected