Skip to content

Commit

Permalink
Added Snippet: Virtual functions in c++, Added Snippet: Custom compon…
Browse files Browse the repository at this point in the history
…ents in Unreal Engine C++, Added Snippet: Exposing Static Constant to Blueprint from Unreal Engine C++, Minor Fixes
  • Loading branch information
ManasMakde committed Dec 20, 2024
1 parent 5f0ad1b commit 2d4772f
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 5 deletions.
12 changes: 12 additions & 0 deletions _mdx/snippets/Cpp/virtual-functions-in-cpp/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { HTMLSkeleton, H1 } from "./global.jsx"


export const snippet_title = "Virtual Functions in C++"
export const snippet_category = "C++"


<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }}>

<H1>{snippet_title}</H1>

</HTMLSkeleton>
20 changes: 20 additions & 0 deletions _mdx/snippets/Unreal Engine/ue-custom-component/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { HTMLSkeleton, H1 } from "./global.jsx"

export const snippet_title = "Custom components in Unreal Engine C++"
export const snippet_category = "Unreal Engine"

<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }} UseLocalGuide={true}>

<H1>{snippet_title}</H1>

```cpp
#include "Components/ActorComponent.h"

UCLASS(meta=(BlueprintSpawnableComponent)) // without this the component will not show in blueprints
class MYPROJECT_API UExampleComponent : public UActorComponent
{
GENERATED_BODY()

};
```
</HTMLSkeleton>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { HTMLSkeleton, H1 } from "./global.jsx"

export const snippet_title = "Exposing Static Constant to Blueprint from C++ in Unreal Engine"
export const snippet_category = "Unreal Engine"

<HTMLSkeleton RegisterToSiteGuide={{ category : snippet_category, title : snippet_title }} UseLocalGuide={true}>

<H1>{snippet_title}</H1>

**Note:** this is more of a workaround

```cpp
// ExampleObject.h file

UCLASS()
class MYPROJECT_API UExampleStatic : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintPure)
static float GetMyConstant();
};


UCLASS()
class MYPROJECT_API UExampleObject : public UObject {
GENERATED_BODY()

public:
static const float MY_CONSTANT; // Exposing to blueprints via Function Library

};
```

```cpp
// ExampleObject.cpp file

const float UExampleObject::MY_CONSTANT = 10.5f;

float UExampleStatic::GetMyConstant(){ return UExampleObject::MY_CONSTANT; }
```
</HTMLSkeleton>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HTMLSkeleton, H1, H2, H3, LocalGuide } from "./global.jsx"
import { HTMLSkeleton, H1, H2, LocalGuide } from "./global.jsx"

export const snippet_title = "UInterfaces in Unreal Engine C++"
export const snippet_category = "Unreal Engine"
Expand Down Expand Up @@ -59,7 +59,7 @@ class MYPROJECT_API IExampleInterface
...

UCLASS()
class TESTING_API AExampleCharacter : public ACharacter, public IExampleInterface
class MYPROJECT_API AExampleCharacter : public ACharacter, public IExampleInterface
{
GENERATED_BODY()

Expand Down
2 changes: 1 addition & 1 deletion _static/siteguide.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"/snippets/unreal-engine/unreal-engine-udelegates/":{"category":"Unreal Engine","title":"UDelegates in Unreal Engine C++"},"/snippets/unreal-engine/unreal-engine-uenums/":{"category":"Unreal Engine","title":"UEnums in Unreal Engine C++"},"/snippets/unreal-engine/unreal-engine-uinterfaces/":{"category":"Unreal Engine","title":"UInterfaces in Unreal Engine C++"},"/snippets/unreal-engine/unreal-engine-ustructs/":{"category":"Unreal Engine","title":"UStructs in Unreal Engine C++"},"/snippets/cpp/cpp-hello-world/":{"category":"C++","title":"Hello World in C++"}}
{"/snippets/unreal-engine/ue-uinterfaces/":{"category":"Unreal Engine","title":"UInterfaces in Unreal Engine C++"},"/snippets/unreal-engine/ue-udelegates/":{"category":"Unreal Engine","title":"UDelegates in Unreal Engine C++"},"/snippets/unreal-engine/ue-custom-component/":{"category":"Unreal Engine","title":"Custom components in Unreal Engine C++"},"/snippets/unreal-engine/ue-expose-static-constant-to-bp/":{"category":"Unreal Engine","title":"Exposing Static Constant to Blueprint from C++ in Unreal Engine"},"/snippets/unreal-engine/ue-uenums/":{"category":"Unreal Engine","title":"UEnums in Unreal Engine C++"},"/snippets/unreal-engine/ue-ustructs/":{"category":"Unreal Engine","title":"UStructs in Unreal Engine C++"},"/snippets/cpp/virtual-functions-in-cpp/":{"category":"C++","title":"Virtual Functions in C++"},"/snippets/cpp/cpp-hello-world/":{"category":"C++","title":"Hello World in C++"}}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SourceSnippet</title></head><body><h1>Welcome to <a href="https://github.com/sourcesnippet/sourcesnippet.github.io" style="color:CanvasText;text-decoration:underline">SourceSnippet</a></h1><div style="opacity:.75"> - Years of experience, Stored in snippets </div><hr><br><h1>Unreal Engine</h1><ol><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/unreal-engine-udelegates/">UDelegates in Unreal Engine C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/unreal-engine-uenums/">UEnums in Unreal Engine C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/unreal-engine-uinterfaces/">UInterfaces in Unreal Engine C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/unreal-engine-ustructs/">UStructs in Unreal Engine C++</a></li></ol><br><h1>C++</h1><ol><li style="margin-top:1rem"><a target="_blank" href="/snippets/cpp/cpp-hello-world/">Hello World in C++</a></li></ol><style>body{background-color:Canvas;color:CanvasText;color-scheme:light dark;font-size:18px;margin:0 auto;max-width:700px;line-height:1.3;padding:40px 1rem}a{text-decoration:none}a:hover{text-decoration:underline}</style></body></html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>SourceSnippet</title></head><body><h1>Welcome to <a href="https://github.com/sourcesnippet/sourcesnippet.github.io" style="color:CanvasText;text-decoration:underline">SourceSnippet</a></h1><div style="opacity:.75"> - Years of experience, Stored in snippets </div><hr><br><h1>Unreal Engine</h1><ol><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/ue-custom-component/">Custom components in Unreal Engine C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/ue-expose-static-constant-to-bp/">Exposing Static Constant to Blueprint from C++ in Unreal Engine</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/ue-udelegates/">UDelegates in Unreal Engine C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/ue-uenums/">UEnums in Unreal Engine C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/ue-uinterfaces/">UInterfaces in Unreal Engine C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/unreal-engine/ue-ustructs/">UStructs in Unreal Engine C++</a></li></ol><br><h1>C++</h1><ol><li style="margin-top:1rem"><a target="_blank" href="/snippets/cpp/cpp-hello-world/">Hello World in C++</a></li><li style="margin-top:1rem"><a target="_blank" href="/snippets/cpp/virtual-functions-in-cpp/">Virtual Functions in C++</a></li></ol><style>body{background-color:Canvas;color:CanvasText;color-scheme:light dark;font-size:18px;margin:0 auto;max-width:700px;line-height:1.3;padding:40px 1rem}a{text-decoration:none}a:hover{text-decoration:underline}</style></body></html>
1 change: 1 addition & 0 deletions snippets/cpp/virtual-functions-in-cpp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Virtual Functions in C++ - SourceSnippet</title><link rel="stylesheet" href="/_static/codestyle.css"><style>body{background-color:Canvas;color:CanvasText;color-scheme:light dark;font-size:18px;margin:0 auto;max-width:700px;line-height:1.3;padding:40px 1rem}</style></head><body><h1>Virtual Functions in C++</h1><hr><br></body></html>
9 changes: 9 additions & 0 deletions snippets/unreal-engine/ue-custom-component/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Custom components in Unreal Engine C++ - SourceSnippet</title><link rel="stylesheet" href="/_static/codestyle.css"><style>body{background-color:Canvas;color:CanvasText;color-scheme:light dark;font-size:18px;margin:0 auto;max-width:700px;line-height:1.3;padding:40px 1rem}</style></head><body><h1>Custom components in Unreal Engine C++</h1><hr><br><pre><code class="hljs language-cpp"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string">&quot;Components/ActorComponent.h&quot;</span></span>

<span class="hljs-built_in">UCLASS</span>(meta=(BlueprintSpawnableComponent)) <span class="hljs-comment">// without this the component will not show in blueprints </span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MYPROJECT_API</span> UExampleComponent : <span class="hljs-keyword">public</span> UActorComponent
{
<span class="hljs-built_in">GENERATED_BODY</span>()

};
</code></pre></body></html>
27 changes: 27 additions & 0 deletions snippets/unreal-engine/ue-expose-static-constant-to-bp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Exposing Static Constant to Blueprint from C++ in Unreal Engine - SourceSnippet</title><link rel="stylesheet" href="/_static/codestyle.css"><style>body{background-color:Canvas;color:CanvasText;color-scheme:light dark;font-size:18px;margin:0 auto;max-width:700px;line-height:1.3;padding:40px 1rem}</style></head><body><h1>Exposing Static Constant to Blueprint from C++ in Unreal Engine</h1><hr><br><p><strong>Note:</strong> this is more of a workaround</p><pre><code class="hljs language-cpp"><span class="hljs-comment">// ExampleObject.h file</span>

<span class="hljs-built_in">UCLASS</span>()
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MYPROJECT_API</span> UExampleStatic : <span class="hljs-keyword">public</span> UBlueprintFunctionLibrary
{
<span class="hljs-built_in">GENERATED_BODY</span>()

<span class="hljs-keyword">public</span>:
<span class="hljs-built_in">UFUNCTION</span>(BlueprintPure)
<span class="hljs-function"><span class="hljs-type">static</span> <span class="hljs-type">float</span> <span class="hljs-title">GetMyConstant</span><span class="hljs-params">()</span></span>;
};


<span class="hljs-built_in">UCLASS</span>()
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MYPROJECT_API</span> UExampleObject : <span class="hljs-keyword">public</span> UObject {
<span class="hljs-built_in">GENERATED_BODY</span>()

<span class="hljs-keyword">public</span>:
<span class="hljs-type">static</span> <span class="hljs-type">const</span> <span class="hljs-type">float</span> MY_CONSTANT; <span class="hljs-comment">// Exposing to blueprints via Function Library</span>

};
</code></pre><pre><code class="hljs language-cpp"><span class="hljs-comment">// ExampleObject.cpp file</span>

<span class="hljs-type">const</span> <span class="hljs-type">float</span> UExampleObject::MY_CONSTANT = <span class="hljs-number">10.5f</span>;

<span class="hljs-function"><span class="hljs-type">float</span> <span class="hljs-title">UExampleStatic::GetMyConstant</span><span class="hljs-params">()</span></span>{ <span class="hljs-keyword">return</span> UExampleObject::MY_CONSTANT; }
</code></pre></body></html>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
...

<span class="hljs-built_in">UCLASS</span>()
<span class="hljs-keyword">class</span> <span class="hljs-title class_">TESTING_API</span> AExampleCharacter : <span class="hljs-keyword">public</span> ACharacter, <span class="hljs-keyword">public</span> IExampleInterface
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MYPROJECT_API</span> AExampleCharacter : <span class="hljs-keyword">public</span> ACharacter, <span class="hljs-keyword">public</span> IExampleInterface
{
<span class="hljs-built_in">GENERATED_BODY</span>()

Expand Down

0 comments on commit 2d4772f

Please sign in to comment.