UGameplayStatics::HasOption
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticBlueprintPure
Description
Returns true if the specified key exists anywhere in a URL options string, regardless of its associated value. Use this before ParseOption when you need to distinguish a key with an empty value from a missing key.
Caveats & Gotchas
- • A key present with an empty value (e.g. '?Spectate=') will return true; use HasOption to detect presence, then ParseOption only when the value itself matters.
- • Like ParseOption, the comparison is case-insensitive and Options is taken by value so the caller's string is not modified.
Signature
static ENGINE_API bool HasOption( FString Options, const FString& InKey ); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Options | FString | The full options string to search. | — |
| InKey | const FString& | The key to check for existence. | — |
Return Type
bool Example
Conditional logic based on flag presence in InitGame C++
void AMyGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
Super::InitGame(MapName, Options, ErrorMessage);
if (UGameplayStatics::HasOption(Options, TEXT("Spectate")))
{
bAllowSpectators = true;
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?