0%

实用 Unreal Engine API

摘要

一些实用的Unreal Engine API方便查找

基于UKismetSystemLibrary

转自 : https://www.cnblogs.com/shiroe/p/14743901.html

获取各类名称

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Returns the actual object name.
UFUNCTION(BlueprintPure, Category = "Utilities")
static FString GetObjectName(const UObject* Object);

// Returns the full path to the specified object.
UFUNCTION(BlueprintPure, Category="Utilities")
static FString GetPathName(const UObject* Object);

// Returns the display name (or actor label), for displaying as a debugging aid.
// Note: In editor builds, this is the actor label. In non-editor builds, this is the actual object name. This function should not be used to uniquely identify actors!
// It is not localized and should not be used for display to an end user of a game.
UFUNCTION(BlueprintPure, Category="Utilities")
static FString GetDisplayName(const UObject* Object);

// Returns the display name of a class
UFUNCTION(BlueprintPure, Category = "Utilities", meta = (DisplayName = "Get Display Name"))
static FString GetClassDisplayName(UClass* Class);

// Engine build number, for displaying to end users.
UFUNCTION(BlueprintPure, Category="Development", meta=(BlueprintThreadSafe))
static FString GetEngineVersion();

/** Get the name of the current game */
UFUNCTION(BlueprintPure, Category="Game", meta=(BlueprintThreadSafe))
static FString GetGameName();

/** Get the current user name from the OS */
UFUNCTION(BlueprintPure, Category="Utilities|Platform")
static FString GetPlatformUserName();

/** Returns the platform specific unique device id */
UFUNCTION(BlueprintPure, Category="Utilities|Platform", meta = (DeprecatedFunction, DeprecationMessage = "Use GetDeviceId instead"))
static FString GetUniqueDeviceId();

/** Returns the platform specific unique device id */
UFUNCTION(BlueprintPure, Category="Utilities|Platform")
static FString GetDeviceId();

获取各种状态

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/** Returns whether the world this object is in is the host or not */
UFUNCTION(BlueprintPure, Category="Networking", meta=(WorldContext="WorldContextObject") )
static bool IsServer(const UObject* WorldContextObject);

/** Returns whether this is running on a dedicated server */
UFUNCTION(BlueprintPure, Category="Networking", meta=(WorldContext="WorldContextObject"))
static bool IsDedicatedServer(const UObject* WorldContextObject);

/** Returns whether this game instance is stand alone (no networking). */
UFUNCTION(BlueprintPure, Category="Networking", meta=(WorldContext="WorldContextObject"))
static bool IsStandalone(const UObject* WorldContextObject);

/** Returns whether we're currently running in split screen (more than one local player). */
UFUNCTION(BlueprintPure, Category = "Utilities", meta = (WorldContext = "WorldContextObject"))
static bool IsSplitScreen(const UObject* WorldContextObject);

/** Returns whether this is a build that is packaged for distribution */
UFUNCTION(BlueprintPure, Category="Development", meta=(BlueprintThreadSafe))
static bool IsPackagedForDistribution();

获取时间

1
2
3
4
5
6
7
8
9
10
11
12
/** 
* Get the current game time, in seconds. This stops when the game is paused and is affected by slomo.
*
* @param WorldContextObject World context
*/
UFUNCTION(BlueprintPure, Category="Utilities|Time", meta=(WorldContext="WorldContextObject") )
static float GetGameTimeInSeconds(const UObject* WorldContextObject);

/** Returns the value of GFrameCounter, a running count of the number of frames that have occurred. */
UFUNCTION(BlueprintPure, Category = "Utilities")
static int64 GetFrameCount();

获取常见路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Returns the full system path to a UObject
// If given a non-asset UObject, it will return an empty string
UFUNCTION(BlueprintPure, Category = "Utilities")
static FString GetSystemPath(const UObject* Object);

/** Get the directory of the current project */
UFUNCTION(BlueprintPure, Category="Utilities|Paths", meta=(BlueprintThreadSafe))
static FString GetProjectDirectory();

/** Get the content directory of the current project */
UFUNCTION(BlueprintPure, Category="Utilities|Paths", meta=(BlueprintThreadSafe))
static FString GetProjectContentDirectory();

/** Get the saved directory of the current project */
UFUNCTION(BlueprintPure, Category="Utilities|Paths", meta=(BlueprintThreadSafe))
static FString GetProjectSavedDirectory();

/** Get the current user dir from the OS */
UFUNCTION(BlueprintPure, Category = "Utilities|Platform")
static FString GetPlatformUserDir();

路径转换

1
2
3
4
5
6
7
8
9
10
11
12
/* Converts passed in filename to use a relative path */
UFUNCTION(BlueprintPure, Category="Utilities|Paths")
static FString ConvertToRelativePath(const FString& Filename);

/* Converts passed in filename to use a absolute path */
UFUNCTION(BlueprintPure, Category="Utilities|Paths")
static FString ConvertToAbsolutePath(const FString& Filename);

/* Convert all / and \ to TEXT("/") */
UFUNCTION(BlueprintPure, Category="Utilities|Paths", meta=(BlueprintThreadSafe))
static FString NormalizeFilename(const FString& InFilename);

FPaths —— 更全的路径

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
/**
* Path helpers for retrieving game dir, engine dir, etc.
*/
class CORE_API FPaths
{
public:

/**
* Should the "saved" directory structures be rooted in the user dir or relative to the "engine/game"
*/
static bool ShouldSaveToUserDir();

/**
* Returns the directory the application was launched from (useful for commandline utilities)
*/
static FString LaunchDir();

/**
* Returns the base directory of the "core" engine that can be shared across
* several games or across games & mods. Shaders and base localization files
* e.g. reside in the engine directory.
*
* @return engine directory
*/
static FString EngineDir();

/**
* Returns the root directory for user-specific engine files. Always writable.
*
* @return root user directory
*/
static FString EngineUserDir();

/**
* Returns the root directory for user-specific engine files which can be shared between versions. Always writable.
*
* @return root user directory
*/
static FString EngineVersionAgnosticUserDir();

/**
* Returns the content directory of the "core" engine that can be shared across
* several games or across games & mods.
*
* @return engine content directory
*/
static FString EngineContentDir();

/**
* Returns the directory the root configuration files are located.
*
* @return root config directory
*/
static FString EngineConfigDir();

/**
* Returns the Editor Settings directory of the engine
*
* @return Editor Settings directory.
*/
static FString EngineEditorSettingsDir();

/**
* Returns the intermediate directory of the engine
*
* @return content directory
*/
static FString EngineIntermediateDir();

/**
* Returns the saved directory of the engine
*
* @return Saved directory.
*/
static FString EngineSavedDir();

/**
* Returns the plugins directory of the engine
*
* @return Plugins directory.
*/
static FString EnginePluginsDir();

/**
* Returns the directory for default Editor UI Layout files of the engine
* @return Directory for default Editor UI Layout files.
*/
static FString EngineDefaultLayoutDir();

/**
* Returns the directory for project Editor UI Layout files of the engine
* @return Directory for project Editor UI Layout files.
*/
static FString EngineProjectLayoutDir();

/**
* Returns the directory for user-generated Editor UI Layout files of the engine
* @return Directory for user-generated Editor UI Layout files.
*/
static FString EngineUserLayoutDir();

/**
* Returns the base directory enterprise directory.
*
* @return enterprise directory
*/
static FString EnterpriseDir();

/**
* Returns the enterprise plugins directory
*
* @return Plugins directory.
*/
static FString EnterprisePluginsDir();

/**
* Returns the enterprise FeaturePack directory
*
* @return FeaturePack directory.
*/
static FString EnterpriseFeaturePackDir();

/**
* Returns the directory where engine platform extensions reside
*
* @return engine platform extensions directory
*/
static FString EnginePlatformExtensionsDir();

/**
* Returns the directory where the project's platform extensions reside
*
* @return project platform extensions directory
*/
static FString ProjectPlatformExtensionsDir();

/**
* Returns platform and restricted extensions that are present and valid (for platforms, it uses FDataDrivePlatformInfo to determine valid platforms, it doesn't just use what's present)
*
* @return BaseDir and usable extension directories under BaseDir (either Engine or Project)
*/
static TArray<FString> GetExtensionDirs(const FString& BaseDir, const FString& SubDir=FString());

/**
* Returns the root directory of the engine directory tree
*
* @return Root directory.
*/
static FString RootDir();

/**
* Returns the base directory of the current project by looking at FApp::GetProjectName().
* This is usually a subdirectory of the installation
* root directory and can be overridden on the command line to allow self
* contained mod support.
*
* @return base directory
*/
static FString ProjectDir();

/**
* Returns the root directory for user-specific game files.
*
* @return game user directory
*/
static FString ProjectUserDir();

/**
* Returns the content directory of the current game by looking at FApp::GetProjectName().
*
* @return content directory
*/
static FString ProjectContentDir();

/**
* Returns the directory the root configuration files are located.
*
* @return root config directory
*/
static FString ProjectConfigDir();

/**
* Returns the saved directory of the current game by looking at FApp::GetProjectName().
*
* @return saved directory
*/
static const FString& ProjectSavedDir();

/**
* Returns the intermediate directory of the current game by looking at FApp::GetProjectName().
*
* @return intermediate directory
*/
static FString ProjectIntermediateDir();

static FString ShaderWorkingDir();

/**
* Returns the plugins directory of the current game by looking at FApp::GetProjectName().
*
* @return plugins directory
*/
static FString ProjectPluginsDir();

/**
* Returns the mods directory of the current project by looking at FApp::GetProjectName().
*
* @return mods directory
*/
static FString ProjectModsDir();

/*
* Returns true if a writable directory for downloaded data that persists across play sessions is available
*/
static bool HasProjectPersistentDownloadDir();

/*
* Returns the writable directory for downloaded data that persists across play sessions.
*/
static FString ProjectPersistentDownloadDir();

/**
* Returns the directory the engine uses to look for the source leaf ini files. This
* can't be an .ini variable for obvious reasons.
*
* @return source config directory
*/
static FString SourceConfigDir();

/**
* Returns the directory the engine saves generated config files.
*
* @return config directory
*/
static FString GeneratedConfigDir();

/**
* Returns the directory the engine stores sandbox output
*
* @return sandbox directory
*/
static FString SandboxesDir();

/**
* Returns the directory the engine uses to output profiling files.
*
* @return log directory
*/
static FString ProfilingDir();

/**
* Returns the directory the engine uses to output screenshot files.
*
* @return screenshot directory
*/
static FString ScreenShotDir();

/**
* Returns the directory the engine uses to output BugIt files.
*
* @return screenshot directory
*/
static FString BugItDir();

/**
* Returns the directory the engine uses to output user requested video capture files.
*
* @return Video capture directory
*/
static FString VideoCaptureDir();

/**
* Returns the directory the engine uses to output logs. This currently can't
* be an .ini setting as the game starts logging before it can read from .ini
* files.
*
* @return log directory
*/
static FString ProjectLogDir();

/** Returns the directory for automation save files */
static FString AutomationDir();

/** Returns the directory for automation save files that are meant to be deleted every run */
static FString AutomationTransientDir();

/** Returns the directory for results of automation tests. May be deleted every run. */
static FString AutomationReportsDir();

/** Returns the directory for automation log files */
static FString AutomationLogDir();

/** Returns the directory for local files used in cloud emulation or support */
static FString CloudDir();

/** Returns the directory that contains subfolders for developer-specific content */
static FString GameDevelopersDir();

/** Returns The folder name for the developer-specific directory for the current user */
static FString GameUserDeveloperFolderName();

/** Returns The directory that contains developer-specific content for the current user */
static FString GameUserDeveloperDir();

/** Returns the directory for temp files used for diffing */
static FString DiffDir();

/**
* Returns a list of engine-specific localization paths
*/
static const TArray<FString>& GetEngineLocalizationPaths();

/**
* Returns a list of editor-specific localization paths
*/
static const TArray<FString>& GetEditorLocalizationPaths();

/**
* Returns a list of property name localization paths
*/
static const TArray<FString>& GetPropertyNameLocalizationPaths();

/**
* Returns a list of tool tip localization paths
*/
static const TArray<FString>& GetToolTipLocalizationPaths();

/**
* Returns a list of game-specific localization paths
*/
static const TArray<FString>& GetGameLocalizationPaths();

/**
* Get the name of the platform-specific localization sub-folder
*/
static FString GetPlatformLocalizationFolderName();

/**
* Returns a list of restricted/internal folder names (without any slashes) which may be tested against full paths to determine if a path is restricted or not.
*/
static const TArray<FString>& GetRestrictedFolderNames();

/**
* Determines if supplied path uses a restricted/internal subdirectory. Note that slashes are normalized and character case is ignored for the comparison.
*/
static bool IsRestrictedPath(const FString& InPath);

/**
* Returns the saved directory that is not game specific. This is usually the same as
* EngineSavedDir().
*
* @return saved directory
*/
static FString GameAgnosticSavedDir();

/** Returns the directory where engine source code files are kept */
static FString EngineSourceDir();

/** Returns the directory where game source code files are kept */
static FString GameSourceDir();

/** Returns the directory where feature packs are kept */
static FString FeaturePackDir();

/**
* Checks whether the path to the project file, if any, is set.
*
* @return true if the path is set, false otherwise.
*/
static bool IsProjectFilePathSet();

/**
* Gets the path to the project file.
*
* @return Project file path.
*/
static FString GetProjectFilePath();

/**
* Sets the path to the project file.
*
* @param NewGameProjectFilePath - The project file path to set.
*/
static void SetProjectFilePath( const FString& NewGameProjectFilePath );

/**
* Gets the extension for this filename.
*
* @param bIncludeDot if true, includes the leading dot in the result
*
* @return the extension of this filename, or an empty string if the filename doesn't have an extension.
*/
static FString GetExtension( const FString& InPath, bool bIncludeDot=false );

// Returns the filename (with extension), minus any path information.
static FString GetCleanFilename(const FString& InPath);

// Returns the filename (with extension), minus any path information.
static FString GetCleanFilename(FString&& InPath);

// Returns the same thing as GetCleanFilename, but without the extension
static FString GetBaseFilename(const FString& InPath, bool bRemovePath=true );

// Returns the same thing as GetCleanFilename, but without the extension
static FString GetBaseFilename(FString&& InPath, bool bRemovePath = true);

// Returns the path in front of the filename
static FString GetPath(const FString& InPath);

// Returns the path in front of the filename
static FString GetPath(FString&& InPath);

// Returns the leaf in the path
static FString GetPathLeaf(const FString& InPath);

// Returns the leaf in the path
static FString GetPathLeaf(FString&& InPath);

/** Changes the extension of the given filename (does nothing if the file has no extension) */
static FString ChangeExtension(const FString& InPath, const FString& InNewExtension);

/** Sets the extension of the given filename (like ChangeExtension, but also applies the extension if the file doesn't have one) */
static FString SetExtension(const FString& InPath, const FString& InNewExtension);

/** Returns true if this file was found, false otherwise */
static bool FileExists(const FString& InPath);

/** Returns true if this directory was found, false otherwise */
static bool DirectoryExists(const FString& InPath);

/** Returns true if this path represents a root drive or volume */
static bool IsDrive(const FString& InPath);

/** Returns true if this path is relative to another path */
static bool IsRelative(const FString& InPath);

/** Convert all / and \ to TEXT("/") */
static void NormalizeFilename(FString& InPath);

/**
* Checks if two paths are the same.
*
* @param PathA First path to check.
* @param PathB Second path to check.
*
* @returns True if both paths are the same. False otherwise.
*/
static bool IsSamePath(const FString& PathA, const FString& PathB);

/** Determines if a path is under a given directory */
static bool IsUnderDirectory(const FString& InPath, const FString& InDirectory);

/** Normalize all / and \ to TEXT("/") and remove any trailing TEXT("/") if the character before that is not a TEXT("/") or a colon */
static void NormalizeDirectoryName(FString& InPath);

/**
* Takes a fully pathed string and eliminates relative pathing (eg: annihilates ".." with the adjacent directory).
* Assumes all slashes have been converted to TEXT('/').
* For example, takes the string:
* BaseDirectory/SomeDirectory/../SomeOtherDirectory/Filename.ext
* and converts it to:
* BaseDirectory/SomeOtherDirectory/Filename.ext
*/
static bool CollapseRelativeDirectories(FString& InPath);

/**
* Removes duplicate slashes in paths.
* Assumes all slashes have been converted to TEXT('/').
* For example, takes the string:
* BaseDirectory/SomeDirectory//SomeOtherDirectory////Filename.ext
* and converts it to:
* BaseDirectory/SomeDirectory/SomeOtherDirectory/Filename.ext
*/
static void RemoveDuplicateSlashes(FString& InPath);

/**
* Make fully standard "Unreal" pathname:
* - Normalizes path separators [NormalizeFilename]
* - Removes extraneous separators [NormalizeDirectoryName, as well removing adjacent separators]
* - Collapses internal ..'s
* - Makes relative to Engine\Binaries\<Platform> (will ALWAYS start with ..\..\..)
*/
static FString CreateStandardFilename(const FString& InPath);

static void MakeStandardFilename(FString& InPath);

/** Takes an "Unreal" pathname and converts it to a platform filename. */
static void MakePlatformFilename(FString& InPath);

/**
* Assuming both paths (or filenames) are relative to the same base dir, modifies InPath to be relative to InRelativeTo
*
* @param InPath Path to change to be relative to InRelativeTo
* @param InRelativeTo Path to use as the new relative base
* @returns true if InPath was changed to be relative
*/
static bool MakePathRelativeTo( FString& InPath, const TCHAR* InRelativeTo );

/**
* Converts a relative path name to a fully qualified name relative to the process BaseDir().
*/
static FString ConvertRelativePathToFull(const FString& InPath);

/**
* Converts a relative path name to a fully qualified name relative to the process BaseDir().
*/
static FString ConvertRelativePathToFull(FString&& InPath);

/**
* Converts a relative path name to a fully qualified name relative to the specified BasePath.
*/
static FString ConvertRelativePathToFull(const FString& BasePath, const FString& InPath);

/**
* Converts a relative path name to a fully qualified name relative to the specified BasePath.
*/
static FString ConvertRelativePathToFull(const FString& BasePath, FString&& InPath);

/**
* Converts a relative path name to a fully qualified name relative to the specified BasePath.
*/
static FString ConvertRelativePathToFull(FString&& BasePath, const FString& InPath);

/**
* Converts a relative path name to a fully qualified name relative to the specified BasePath.
*/
static FString ConvertRelativePathToFull(FString&& BasePath, FString&& InPath);

/**
* Converts a normal path to a sandbox path (in Saved/Sandboxes).
*
* @param InSandboxName The name of the sandbox.
*/
static FString ConvertToSandboxPath( const FString& InPath, const TCHAR* InSandboxName );

/**
* Converts a sandbox (in Saved/Sandboxes) path to a normal path.
*
* @param InSandboxName The name of the sandbox.
*/
static FString ConvertFromSandboxPath( const FString& InPath, const TCHAR* InSandboxName );

/**
* Creates a temporary filename with the specified prefix.
*
* @param Path The file pathname.
* @param Prefix The file prefix.
* @param Extension File extension ('.' required).
*/
static FString CreateTempFilename( const TCHAR* Path, const TCHAR* Prefix = TEXT(""), const TCHAR* Extension = TEXT(".tmp") );

/**
* Returns a string containing all invalid characters as dictated by the operating system
*/
static FString GetInvalidFileSystemChars();

/**
* Returns a string that is safe to use as a filename because all items in
* GetInvalidFileSystemChars() are removed
*/
static FString MakeValidFileName(const FString& InString, const TCHAR InReplacementChar=0);

/**
* Validates that the parts that make up the path contain no invalid characters as dictated by the operating system
* Note that this is a different set of restrictions to those imposed by FPackageName
*
* @param InPath - path to validate
* @param OutReason - optional parameter to fill with the failure reason
*/
static bool ValidatePath( const FString& InPath, FText* OutReason = nullptr );

/**
* Parses a fully qualified or relative filename into its components (filename, path, extension).
*
* @param Path [out] receives the value of the path portion of the input string
* @param Filename [out] receives the value of the filename portion of the input string
* @param Extension [out] receives the value of the extension portion of the input string
*/
static void Split( const FString& InPath, FString& PathPart, FString& FilenamePart, FString& ExtensionPart );

/** Gets the relative path to get from BaseDir to RootDirectory */
static const FString& GetRelativePathToRoot();

template <typename... PathTypes>
FORCEINLINE static FString Combine(PathTypes&&... InPaths)
{
const TCHAR* Paths[] = { GetTCharPtr(Forward<PathTypes>(InPaths))... };
FString Out;

CombineInternal(Out, Paths, UE_ARRAY_COUNT(Paths));
return Out;
}

/**
* Frees any memory retained by FPaths.
*/
static void TearDown();

protected:

static void CombineInternal(FString& OutPath, const TCHAR** Paths, int32 NumPaths);

private:
struct FStaticData;

FORCEINLINE static const TCHAR* GetTCharPtr(const TCHAR* Ptr)
{
return Ptr;
}

FORCEINLINE static const TCHAR* GetTCharPtr(const FString& Str)
{
return *Str;
}

/** Returns, if any, the value of the -userdir command line argument. This can be used to sandbox artifacts to a desired location */
static const FString& CustomUserDirArgument();

/** Returns, if any, the value of the -shaderworkingdir command line argument. This can be used to sandbox shader working files to a desired location */
static const FString& CustomShaderDirArgument();
};

歡迎關注我的其它發布渠道