Skip to content

Commit b620eea

Browse files
committed
Added Several snippets & updated existing ones
1 parent f0196e9 commit b620eea

File tree

18 files changed

+344
-43
lines changed

18 files changed

+344
-43
lines changed

_jsx/global.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let GuideGenerationCount = 0 // Keeps count of guide generation, deletes old gu
3030
// URLS
3131
export const UE_ABSOLUTE_INCLUDE_PATH_URL = "/snippets/unreal-engine/ue-allow-include-path-be-absolute/"
3232
export const UE_CREATING_NEW_OBJECT_URL = "/snippets/unreal-engine-5-cpp/ue-creating-new-objects/"
33-
export const UE_EDIT_OBJECT_IN_EDITOR_URL = "/snippets/unreal-engine-5-cpp/ue-edit-custom-object-in-editor/"
33+
export const UE_EDIT_OBJECT_IN_EDITOR_URL = "/snippets/unreal-engine-5-cpp/ue-create-custom-reusable-objects/"
3434
export const UOBJECT_BLUEPRINT_VARIABLE_DETAILS_PANEL_URL = "https://forums.unrealengine.com/t/uobject-as-blueprint-variable-with-details-panel/445256"
3535

3636

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { HTMLSkeleton, H1 } from "./_jsx/global.jsx"
2+
3+
export const snippet_title = "Boilerplate UBlueprintFunctionLibrary in Unreal Engine 5 C++"
4+
export const snippet_category = "Unreal Engine 5 C++"
5+
6+
<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }}>
7+
8+
<H1>{snippet_title}</H1>
9+
10+
```cpp
11+
// MyBlueprintFunctionLibrary.h file
12+
13+
#pragma once
14+
15+
#include "CoreMinimal.h"
16+
#include "Kismet/BlueprintFunctionLibrary.h"
17+
#include "MyBlueprintFunctionLibrary.generated.h"
18+
19+
/**
20+
*
21+
*/
22+
UCLASS()
23+
class TESTING_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
24+
{
25+
GENERATED_BODY()
26+
27+
};
28+
29+
```
30+
31+
32+
```cpp
33+
// MyBlueprintFunctionLibrary.cpp file
34+
35+
#include "MyBlueprintFunctionLibrary.h"
36+
37+
```
38+
</HTMLSkeleton>

snippets/unreal-engine-5-cpp/ue-boilerplate-uobject/index.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTMLSkeleton, H1 } from "./_jsx/global.jsx"
1+
import { HTMLSkeleton, H1, UE_EDIT_OBJECT_IN_EDITOR_URL } from "./_jsx/global.jsx"
22

33
export const snippet_title = "Boilerplate UObject in Unreal Engine 5 C++"
44
export const snippet_category = "Unreal Engine 5 C++"
@@ -7,6 +7,8 @@ export const snippet_category = "Unreal Engine 5 C++"
77

88
<H1>{snippet_title}</H1>
99

10+
**Note:** For how to _PROPERLY_ create a custom object check <a href={UE_EDIT_OBJECT_IN_EDITOR_URL}>here</a>
11+
1012
```cpp
1113
// MyObject.h file
1214

@@ -30,4 +32,5 @@ class TESTING_API UMyObject : public UObject
3032

3133
#include "MyObject.h"
3234
```
35+
3336
</HTMLSkeleton>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { HTMLSkeleton, H1, UE_EDIT_OBJECT_IN_EDITOR_URL } from "./_jsx/global.jsx"
2+
3+
export const snippet_title = "Check if running in editor in Unreal Engine 5 C++"
4+
export const snippet_category = "Unreal Engine 5 C++"
5+
6+
<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }}>
7+
8+
<H1>{snippet_title}</H1>
9+
10+
This will work on all `UObject` derived classes
11+
12+
```cpp
13+
if (UWorld* World = GetWorld()) {
14+
if (World->WorldType == EWorldType::Editor || World->WorldType == EWorldType::EditorPreview) {
15+
return;
16+
}
17+
}
18+
```
19+
20+
</HTMLSkeleton>

snippets/unreal-engine-5-cpp/ue-edit-custom-object-in-editor/index.mdx renamed to snippets/unreal-engine-5-cpp/ue-create-custom-reusable-objects/index.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HTMLSkeleton, H1, UOBJECT_BLUEPRINT_VARIABLE_DETAILS_PANEL_URL } from "./_jsx/global.jsx"
22

3-
export const snippet_title = "Edit Custom Object in Editor in Unreal Engine 5 C++"
3+
export const snippet_title = "Create custom reusable Objects in Unreal Engine 5 C++"
44
export const snippet_category = "Unreal Engine 5 C++"
55

66
<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }}>
@@ -9,7 +9,7 @@ export const snippet_category = "Unreal Engine 5 C++"
99

1010
```cpp
1111
// MyObject.h
12-
UCLASS(DefaultToInstanced, EditInlineNew, Blueprintable) // Add DefaultToInstanced & EditInlineNew
12+
UCLASS(DefaultToInstanced, EditInlineNew, Blueprintable) // Do NOT forget to add `DefaultToInstanced` & `EditInlineNew`
1313
class TESTING_API UMyObject : public UObject {
1414

1515
GENERATED_BODY()
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { HTMLSkeleton, H1 } from "./_jsx/global.jsx"
2+
3+
export const snippet_title = "Invoking UFunction by name via ProcessEvent in Unreal Engine 5 C++"
4+
export const snippet_category = "Unreal Engine 5 C++"
5+
6+
<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }}>
7+
8+
<H1 WrittenOn={new Date("2024-07-27")}>{snippet_title}</H1>
9+
10+
Example Class:
11+
```cpp
12+
UCLASS()
13+
class TESTING_API UMyObject : public UObject {
14+
GENERATED_BODY()
15+
16+
public:
17+
UFUNCTION()
18+
void MyMethod(){ UE_LOG(LogTemp, Warning, TEXT("MyMethod Invoked")); }
19+
20+
UFUNCTION()
21+
void MyMethodArgs(int32 Value){ UE_LOG(LogTemp, Warning, TEXT("MyMethodArgs called with = %d"), Value); }
22+
};
23+
```
24+
25+
<br/>
26+
27+
Invoking UFunction:
28+
29+
```cpp
30+
// Creating Object
31+
UMyObject* MyObj = NewObject<UMyObject>(this, TEXT("MyObject"));
32+
33+
34+
35+
// Invoking function without arguments
36+
FName MethodName = FName(TEXT("MyMethod"));
37+
UFunction* Func = MyObj->FindFunction(MethodName);
38+
if (Func) {
39+
MyObj->ProcessEvent(Func, nullptr);
40+
}
41+
42+
43+
44+
// Invoking function with arguments
45+
FName MethodArgsName = FName(TEXT("MyMethodArgs"));
46+
UFunction* FuncArgs = MyObj->FindFunction(MethodArgsName);
47+
if (FuncArgs) {
48+
struct
49+
{
50+
int32 Value;
51+
} ParamStruct;
52+
ParamStruct.Value = 56;
53+
54+
MyObj->ProcessEvent(FuncArgs, &ParamStruct);
55+
}
56+
```
57+
</HTMLSkeleton>

snippets/unreal-engine-5-cpp/ue-printing-logging/index.mdx

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,94 @@ export const snippet_category = "Unreal Engine 5 C++"
77

88
<H1>{snippet_title}</H1>
99

10+
11+
## Syntax
1012
```cpp
1113
// Writing On Screen
1214
if(GEngine)
13-
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, TEXT("Some message"));
15+
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, TEXT("Message"));
1416

1517

1618
// Writting in Output Log
17-
UE_LOG(LogTemp, Warning, TEXT("Some message"));
18-
19+
UE_LOG(LogTemp, Warning, TEXT("Message"));
20+
```
1921
22+
<br/>
2023
21-
// print int
24+
## Default datatypes
25+
```cpp
26+
// int
2227
int MyInt = 3;
2328
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("int: %d"), MyInt));
2429
UE_LOG(LogTemp, Warning, TEXT("int: %d"), MyInt);
2530
2631
2732
28-
// print float
33+
// float
2934
float MyFloat = 10.5f;
3035
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("float: %f"), MyFloat));
3136
UE_LOG(LogTemp, Warning, TEXT("float: %f"), MyFloat);
3237
3338
3439
35-
// print boolean
40+
// boolean
3641
bool bMyBool = true;
3742
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("bool: %s"), bMyBool ? TEXT("true") : TEXT("false")));
3843
UE_LOG(LogTemp, Warning, TEXT("bool: %s"), bMyBool ? TEXT("true") : TEXT("false"));
44+
```
45+
46+
<br/>
3947

4048

49+
## Unreal datatypes
4150

42-
// print enum
51+
```cpp
52+
// Enum
4353
ECustomEnum EMyEnum = ECustomEnum::ValueA;
4454
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("Enum: %s"), *UEnum::GetValueAsString(EMyEnum)));
4555
UE_LOG(LogTemp, Warning, TEXT("Enum: %s"), *UEnum::GetValueAsString(EMyEnum));
4656

4757

4858

49-
// print FString
59+
// FString
5060
FString MyString = TEXT("Hello World");
5161
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("FString: %s"), *MyString));
5262
UE_LOG(LogTemp, Warning, TEXT("FString: %s"), *MyString);
5363

5464

5565

56-
// print FName
66+
// FName
5767
FName MyName = TEXT("Hello World");
5868
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("FName: %s"), *MyName.ToString()));
5969
UE_LOG(LogTemp, Warning, TEXT("FName: %s"), *MyName.ToString());
6070

6171

6272

63-
// print FVector
73+
// FVector
6474
FVector MyVector = FVector(1, 2, 3);
6575
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("FVector: %s"), *MyVector.ToString()));
6676
UE_LOG(LogTemp, Warning, TEXT("FVector: %s"), *MyVector.ToString());
6777

6878

6979

70-
// print UObject
80+
// FRotator
81+
FRotator MyRotator = FRotator(90.0f, 45.0f, 0.0f);
82+
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("FRotator: %s"), *MyRotator.ToString()));
83+
UE_LOG(LogTemp, Warning, TEXT("FRotator: %s"), *MyRotator.ToString());
84+
85+
86+
87+
// UObject
7188
UObject* MyObject = NewObject<UObject>(this, TEXT("MyObject"));
7289
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("UObject: %s"), MyObject ? *MyObject->GetName() : TEXT("NULL")));
7390
UE_LOG(LogTemp, Warning, TEXT("UObject: %s"), MyObject ? *MyObject->GetName() : TEXT("NULL"));
7491

92+
93+
94+
// UClass
95+
UClass* MyClass = UObject::StaticClass();
96+
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Red, FString::Printf(TEXT("UClass: %s"), MyClass ? *MyClass->GetName() : TEXT("NULL")));
97+
UE_LOG(LogTemp, Warning, TEXT("UClass: %s"), MyClass ? *MyClass->GetName() : TEXT("NULL"));
98+
7599
```
76100
</HTMLSkeleton>

snippets/unreal-engine-5-cpp/ue-tmap-tarray-tset/index.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ MyMap[2] = TEXT("New Item 2");
3030
MyMap.Add(4, TEXT("Item 4"));
3131

3232

33+
// Appending
34+
TMap<int, FString> NewMap = {
35+
{5, TEXT("Item 5")},
36+
{6, TEXT("Item 6")},
37+
};
38+
MyMap.Append(NewMap);
39+
40+
3341
// Removing
3442
MyMap.Remove(2);
3543

@@ -94,6 +102,11 @@ MyArray.Add(TEXT("Item 4")); // Adds at the end
94102
MyArray.Insert(TEXT("Item in middle"), 2); // Adds at given index
95103

96104

105+
// Appending
106+
TArray<FString> NewArray = {TEXT("Item 5"), TEXT("Item 6")};
107+
MyArray.Append(NewArray);
108+
109+
97110
// Removing
98111
MyArray.Remove(TEXT("Item 1")); // Finds and removes all matching items
99112
MyArray.RemoveSingle(TEXT("Item 2")); // Finds and removes single matching item
@@ -143,6 +156,11 @@ TSet<FString> MySet = {
143156
MySet.Add(TEXT("Item 5"));
144157
145158
159+
// Appending
160+
TSet<FString> NewSet = { TEXT("Item 6"), TEXT("Item 7") };
161+
MySet.Append(NewSet);
162+
163+
146164
// Removing
147165
MySet.Remove(TEXT("Item 2"));
148166

snippets/unreal-engine-5-cpp/ue-uclass/index.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HTMLSkeleton, H1, H2, UE_EDIT_OBJECT_IN_EDITOR_URL } from "./_jsx/global.jsx"
22

3-
export const snippet_title = "UClass in Unreal Engine 5 C++"
3+
export const snippet_title = "UCLASS in Unreal Engine 5 C++"
44
export const snippet_category = "Unreal Engine 5 C++"
55

66
<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }}>
@@ -42,9 +42,9 @@ BlueprintSpawnableComponent // (If class is a component) Allows the class to be
4242

4343
Abstract // Does not allow the class to be instantiated
4444

45-
DefaultToInstanced
45+
DefaultToInstanced // Makes sure that whenever an object of this class is created it is a unique copy, Using this avoids having to add UPROPERTY(Instanced) everywhere
4646

47-
EditInlineNew
47+
EditInlineNew // Allows properties of an instance of this class to be edited in the details panel
4848
```
4949
5050

snippets/unreal-engine-5-cpp/ue-udelegate/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { HTMLSkeleton, H1 } from "./_jsx/global.jsx"
22

3-
export const snippet_title = "UDelegate in Unreal Engine 5 C++"
3+
export const snippet_title = "UDELEGATE in Unreal Engine 5 C++"
44
export const snippet_category = "Unreal Engine 5 C++"
55

66

0 commit comments

Comments
 (0)