<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Haris</title>
    <description>The latest articles on Forem by Haris (@roasted-kaju).</description>
    <link>https://forem.com/roasted-kaju</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3810700%2Fb1f527af-05cd-4dd9-b598-9ccd1e96f063.gif</url>
      <title>Forem: Haris</title>
      <link>https://forem.com/roasted-kaju</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/roasted-kaju"/>
    <language>en</language>
    <item>
      <title>Unreal Engine 3D Fluid To Flipbook</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sun, 08 Mar 2026 00:15:31 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/unreal-engine-3d-fluid-to-flipbook-41c4</link>
      <guid>https://forem.com/roasted-kaju/unreal-engine-3d-fluid-to-flipbook-41c4</guid>
      <description>&lt;p&gt;I always wanted to create blood VFX using alembics but that turned out to be a bit high end effect which can have a huge file size, it still is perfectly fine to use it for high fidelity games, but it obviously doesn't scale well enough.&lt;/p&gt;

&lt;p&gt;All this time unreal engine had a built-in solution to convert your fluid simulations into flipbooks which you can then use in your particle effects.&lt;/p&gt;

&lt;p&gt;In this section I will go over how to extract flipbook textures from &lt;code&gt;Grid3D_Gas_ColoredSmoke&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw40cq84771ssyrm6g48u.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw40cq84771ssyrm6g48u.jpg" alt=" " width="114" height="185"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a Gas 3D simulation from particle system&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open up this Niagara asset and click on the Baker button&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0fs3obvme53matk6y0x.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc0fs3obvme53matk6y0x.jpg" alt=" " width="800" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Bake menu adjust your camera so you have the particle at the center of your screen&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04uqyhv0usuclogyoddc.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F04uqyhv0usuclogyoddc.jpg" alt=" " width="800" height="576"&gt;&lt;/a&gt;&lt;br&gt;
In the Bake menu adjust your camera so you have the particle at the center of your screen.&lt;/p&gt;

&lt;p&gt;Set name, frame size is best kept at 128, Use Texture Atlas Size to set the resolution 1K or 2K is best for games, Then Click on the Bake button mentioned with a green arrow.&lt;/p&gt;

&lt;p&gt;This will generate a texture atlas like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fab7jrm4yjhw79gsqjd6z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fab7jrm4yjhw79gsqjd6z.jpg" alt=" " width="98" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Our Material
&lt;/h2&gt;

&lt;p&gt;Now before we start to create our 2D Sprite emitter we first are going to setup the material using the Atlas&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z06hba96w83insxoiw9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1z06hba96w83insxoiw9.jpg" alt=" " width="800" height="407"&gt;&lt;/a&gt;&lt;br&gt;
Set the material blend mode to Translucent, Press &lt;code&gt;T&lt;/code&gt; to add a texture sample node, assign the atlas to it.&lt;/p&gt;

&lt;p&gt;To get rid of the black background we divide RGB with Alpha and plug it into the Emissive Color, The Alpha also goes into Opacity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Sprite Emitter
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo7eb7mqjgqsv8vjnuzhh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo7eb7mqjgqsv8vjnuzhh.jpg" alt=" " width="117" height="177"&gt;&lt;/a&gt;&lt;br&gt;
Using this template create a new Particle system.&lt;/p&gt;

&lt;p&gt;Once created Add these 2 modules:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Scale Sprite Size (Optional)&lt;/li&gt;
&lt;li&gt;Sub UV Animation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hvret4ysacope206bfi.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7hvret4ysacope206bfi.jpg" alt=" " width="800" height="670"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxvv0gx2s7jgtjrut8rk.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkxvv0gx2s7jgtjrut8rk.jpg" alt=" " width="800" height="620"&gt;&lt;/a&gt;&lt;br&gt;
And to change the size of our sprite do this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9kw4wauzi75ztoqp3k0.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu9kw4wauzi75ztoqp3k0.jpg" alt=" " width="800" height="446"&gt;&lt;/a&gt;&lt;br&gt;
That is it, you now have a 2D Flip book version of your 3D fluid simulation.&lt;/p&gt;

&lt;p&gt;To Have it loop you have to click the Emitter Update Module and Set it to infinite there and loop delay as well.&lt;/p&gt;

</description>
      <category>gamedev</category>
    </item>
    <item>
      <title>Gameplay Ability System Tips</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 23:34:53 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/gameplay-ability-system-tips-84d</link>
      <guid>https://forem.com/roasted-kaju/gameplay-ability-system-tips-84d</guid>
      <description>&lt;h2&gt;
  
  
  Who Can Have Ability System Component (ASC)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Any actor can have ability system component that includes things like chests, breakable boxes, turrets etc.&lt;/li&gt;
&lt;li&gt;It is recommended to create the base class in C++ because we need to implement the “&lt;code&gt;AbilitySystemInterface&lt;/code&gt;”, it is not needed but it is recommended because with this interface you can use some functions from Ability system library.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best Place to have ASC for Players
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;For a simple single player game, you can have your ASC attached to your player character and initialize with the owner and avatar with player character actor as well.&lt;/li&gt;
&lt;li&gt;The best actor that works for multiplayer is &lt;code&gt;Player State&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Player state exists on server but is replicated to clients as well unlike controllers which only exist on server, if your game is single player you can opt to have your ASC only on controller.&lt;/li&gt;
&lt;li&gt;For AI bots in multiplayer games all you need to do is set &lt;code&gt;bWantsPlayerState&lt;/code&gt; of AI Controller to true.&lt;/li&gt;
&lt;li&gt;Player State is persistence across respawns so all of your de-buffs, cooldowns will remain as they were when you respawn. You will need to manually remove and reset them.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Owner And Avatar
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Owner actor is what persistently represents your character like Controller or Player state, where as Avatar is what physically represents you like Pawn or Character. &lt;/li&gt;
&lt;li&gt;Things like Turret and Boxes can be both Owner and Avatar themselves.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Where to call Init Or Refresh Ability Actor Info
&lt;/h2&gt;

&lt;p&gt;This must be called on both server and client to work.&lt;br&gt;
To Guarantee that PC exists client-side before calling Init is to do this in the Player state’s On Rep function inside the PC, this is done in Lyra as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void ALyraPlayerController::OnRep_PlayerState()
{
    Super::OnRep_PlayerState();
    BroadcastOnPlayerStateChanged();

    // When we're a client connected to a remote server, the player controller may replicate later than the PlayerState and AbilitySystemComponent.
    if (GetWorld()-&amp;gt;IsNetMode(NM_Client))
    {
        if (ALyraPlayerState* LyraPS = GetPlayerState&amp;lt;ALyraPlayerState&amp;gt;())
        {
            if (ULyraAbilitySystemComponent* LyraASC = LyraPS-&amp;gt;GetLyraAbilitySystemComponent())
            {
                // Calls InitAbilityActorInfo
                LyraASC-&amp;gt;RefreshAbilityActorInfo();
                LyraASC-&amp;gt;TryActivateAbilitiesOnSpawn();
            }
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The other part how I handled It was through another function inside the PC, this will do it for client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// For Client, Must be used for initializing the ability system
virtual void AcknowledgePossession(APawn* InPawn) override;

void ARHN_PlayerController::AcknowledgePossession(APawn* InPawn)
{
    Super::AcknowledgePossession(InPawn);

    ARHN_CustomCharacter* C = Cast&amp;lt;ARHN_CustomCharacter&amp;gt;(InPawn);
    if (C)
    {
        C-&amp;gt;GetAbilitySystemComponent()-&amp;gt;InitAbilityActorInfo(C, C);

        // Client / Call this On Server as well
        C-&amp;gt;InitializeAttributes();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For server we would use the character’s Possessed By function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void ARHN_CustomCharacter::PossessedBy(AController* NewController)
{
    Super::PossessedBy(NewController);

    if (ASC)
    {
        ASC-&amp;gt;InitAbilityActorInfo(this, this);
    }

    SetOwner(NewController);

    // Give Ability to Player on the server
    if (ASC &amp;amp;&amp;amp; AbilityToGive &amp;amp;&amp;amp; AbilityToGive2)
    {
        ASC-&amp;gt;GiveAbility(FGameplayAbilitySpec(AbilityToGive.GetDefaultObject(), 1, 0));
        ASC-&amp;gt;GiveAbility(FGameplayAbilitySpec(AbilityToGive2.GetDefaultObject(), 1, 1));
    }

    // Call this when you get respawned
    //ASC-&amp;gt;RefreshAbilityActorInfo();

    // In the future if players rejoin an ongoing session and we don't want to reset attributes, then change this
    // Server / Call this on Client as well
    InitializeAttributes();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Replication Modes
&lt;/h2&gt;

&lt;p&gt;There are three replication modes: Full, Mixed and Minimal.&lt;/p&gt;

&lt;p&gt;Most of time you would be either using Full or Mixed, Mixed is even more common as in Mixed the owning client will receive full Gameplay Effect information where as other clients will only get the tag.&lt;/p&gt;

&lt;p&gt;A Good example of using Full is when other clients need to be able to see the remaining gameplay effect durations that are applied on other clients or bots.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Simulated Touch With Input Swapping In Unreal Engine</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 07:40:50 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/simulated-touch-with-input-swapping-in-unreal-engine-42aa</link>
      <guid>https://forem.com/roasted-kaju/simulated-touch-with-input-swapping-in-unreal-engine-42aa</guid>
      <description>&lt;h2&gt;
  
  
  Problem
&lt;/h2&gt;

&lt;p&gt;So swapping keyboard with touch input is quite easy by default in unreal engine all you need is one function which is called &lt;code&gt;ActivateTouchInterface&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PlayerController-&amp;gt;ActivateTouchInterface(TouchInterface);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you provide no touch interface it will switch your input from touch to mouse and keyboard, but our problem is that our project has pixel streaming enabled which means it always run on a remote PC. To support touch even in that scenario we have to simulate mouse as touch input, this can be done in project settings: &lt;code&gt;Use Mouse for Touch&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can find this setting in &lt;code&gt;Engine→Input&lt;/code&gt; inside your project settings.&lt;/p&gt;

&lt;p&gt;With this option enabled there is now another issue at hand upon switching to keyboard at runtime will mess up your camera controls even if you turn this option off in Input Settings.&lt;/p&gt;

&lt;p&gt;We noticed this bug in our testing phase and found out that this maybe happening because of the &lt;code&gt;DefaultInput&lt;/code&gt; Config is still set to false even if you change your &lt;code&gt;bUseMouseForTouch&lt;/code&gt; inside the input settings.&lt;/p&gt;

&lt;p&gt;Upon manually writing in that &lt;code&gt;DefaultInput&lt;/code&gt; Config still didn’t solve the issue because turns out the engine is still overwriting it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;In order to fix this issue we came across a function inside &lt;code&gt;SlateApplication&lt;/code&gt; there is function called:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void FSlateApplication::SetGameIsFakingTouchEvents(const bool bIsFaking, FVector2D* CursorLocation)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in our function where we swap the inputs we call this function via getting the slate application and it fixed the issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change Platform UI
&lt;/h2&gt;

&lt;p&gt;My UI gets added to viewport on begin play and it pops up 2 buttons which player needs to choose which input mode they want to use.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vc4038496kv8nb5x6n1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7vc4038496kv8nb5x6n1.jpg" alt=" " width="800" height="476"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here is how the Widget blueprint looks like:&lt;br&gt;
&lt;strong&gt;Construct:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv97gkgq550b2jjzdmuv9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fv97gkgq550b2jjzdmuv9.png" alt=" " width="800" height="271"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Desktop Button:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9k1mao32psiqmprr41i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft9k1mao32psiqmprr41i.png" alt=" " width="800" height="174"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Mobile Button:&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7d2o4mokyrw7k14ffk0z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7d2o4mokyrw7k14ffk0z.png" alt=" " width="800" height="266"&gt;&lt;/a&gt;&lt;br&gt;
The main thing you will notice here is that we created a custom function in our game instance class which swaps the input given the &lt;code&gt;UTouchInterface&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Game Instance
&lt;/h2&gt;

&lt;p&gt;Create a new game instance class, honestly it might be better to move this function into player controller but I choose game instance for this example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UFUNCTION(BlueprintCallable, Category = "Input")
    void ToggleTouchInterface(APlayerController* PlayerController, UTouchInterface* TouchInterface);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Implementation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void UMyGameInstance::ToggleTouchInterface(APlayerController* PlayerController, UTouchInterface* TouchInterface)
{
    if (!IsValid(PlayerController))
    {
        return;
    }

    AMyPlayerController* MyPlayerController = Cast&amp;lt;AMyPlayerController&amp;gt;(PlayerController);
    if (IsValid(MyPlayerController))
    {
        return;
    }

    const bool bIsUsingTouch = IsValid(TouchInterface);

    MyPlayerController-&amp;gt;ToggleTouchInput(bIsUsingTouch);

    PlayerController-&amp;gt;ActivateTouchInterface(TouchInterface);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;before calling the &lt;code&gt;ActivateTouchInterface&lt;/code&gt; we run a custom function which we created in our player controller called: &lt;code&gt;ToggleTouchInput&lt;/code&gt; this takes a Boolean as parameter which determines if we are using touch or not.&lt;br&gt;
Toggle Touch Input In Player Controller:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void AMyPlayerController::ToggleTouchInput(bool IsUsingTouch)
{
    UInputSettings* InputSettings = UInputSettings::GetInputSettings();
    if (!InputSettings)
    {
        return;
    }

    InputSettings-&amp;gt;bUseMouseForTouch = IsUsingTouch;
    InputSettings-&amp;gt;SaveConfig();

    FSlateApplication::Get().SetGameIsFakingTouchEvents(IsUsingTouch);

    GConfig-&amp;gt;SetBool(TEXT("/Script/Engine.InputSettings"), TEXT("bAlwaysShowTouchInterface"), IsUsingTouch, FPaths::ProjectConfigDir() + "DefaultInput.ini");
    GConfig-&amp;gt;SetBool(TEXT("/Script/Engine.InputSettings"), TEXT("bUseMouseForTouch"), IsUsingTouch, FPaths::ProjectConfigDir() + "DefaultInput.ini");
    GConfig-&amp;gt;Flush(false, FPaths::ProjectConfigDir() + "DefaultInput.ini");
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing fancy here at first all we are doing is getting and saving the input settings with our new input mode, after that we call the function from Slate application and update our touch mode there as well.&lt;/p&gt;

&lt;p&gt;Once that is finished for sake of full completion we save the Booleans in our Default input config as well.&lt;/p&gt;

&lt;p&gt;Hope this helps, it is quite common for Clients to demand both touch and desktop controls in pixel streaming projects, switching them isn’t as straight forward since you need to be using simulated touch from the get-go.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Pitch Replication And Axis Compression In Unreal Engine</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 07:25:34 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/pitch-replication-and-axis-compression-in-unreal-engine-285k</link>
      <guid>https://forem.com/roasted-kaju/pitch-replication-and-axis-compression-in-unreal-engine-285k</guid>
      <description>&lt;p&gt;Replicating Pitch for using in aim offsets is a quite a common task to come across while building almost any kind of multiplayer game, you want to replicate the look view of other players to know where they are looking or aiming at.&lt;/p&gt;

&lt;p&gt;Quite a lot of young developers will search about this on internet and come across tutorials that manually replicate the pitch value from control rotation, this is all well and good and I myself was one of those guys back in university days starting to learn Unreal I also replicated the pitch using the same way, it was not until I came across Shooter Game where upon seeing the source code I realized that a better and more efficient solution already comes with Unreal Engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Pawn Class
&lt;/h2&gt;

&lt;p&gt;You can use the function called &lt;code&gt;GetBaseAimRotation()&lt;/code&gt; which exists inside the pawn class to get the replicated pitch in blueprints as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Follow these steps:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Get Base Aim Rotation and Get its forward vector.&lt;/li&gt;
&lt;li&gt;Inverse transform the direction from world to local space using the world transform of the pawn itself.&lt;/li&gt;
&lt;li&gt;Break the resultant vector and get pitch.
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjtq7xoj1alj898q91ftz.jpg" alt=" " width="800" height="190"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In C++ you can either use the functions provided by Kismet library or the C++ native functions both do the same thing, If using Kismet Library remember to add it’s respective header.&lt;/p&gt;

&lt;p&gt;Let’s create a function which we can use to get our replicated pitch value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FRotator GetReplicatedPitch() const;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the implementation file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;float AMyCharacter::GetReplicatedPitch() const
{
    const FVector AimDirectionWorld = UKismetMathLibrary::GetForwardVector(GetBaseAimRotation());
    const FVector AimDirectionLocal = UKismetMathLibrary::InverseTransformDirection(GetActorTransform(), AimDirectionWorld);
    const FRotator AimRotationLocal = UKismetMathLibrary::MakeRotFromX(AimDirectionLocal);

    return AimRotationLocal.Pitch;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or if you don’t want to use Kismet Math Library you can easily do the same thing with native functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;float AMyCharacter::GetReplicatedPitch() const
{
    const FVector AimDirectionWorld = GetBaseAimRotation().Vector();
    const FVector AimDirectionLocal = ActorToWorld().InverseTransformVectorNoScale(AimDirectionWorld);
    const FRotator AimRotationLocal = AimDirectionLocal.Rotation();

    return AimRotationLocal.Pitch;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Under The Hood:
&lt;/h2&gt;

&lt;p&gt;You might be curious that how this works under the hood, you can use the same method for replicating other axis or even other values.&lt;/p&gt;

&lt;p&gt;As you have seen the method at the core is called GetBaseAimRotation() this function is divided into two paths, if the player has the controller and if the controller isn’t present AKA If it is a simulated proxy.&lt;/p&gt;

&lt;p&gt;In case of controller being valid the method executes a very simple set of instructions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FVector POVLoc;
FRotator POVRot;
if( Controller != nullptr &amp;amp;&amp;amp; !InFreeCam() )
{
    Controller-&amp;gt;GetPlayerViewPoint(POVLoc, POVRot);
    return POVRot;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We are just getting the player’s eyes or direction at which the player is looking at. However if the controller is not valid:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// If we have no controller, we simply use our rotation
POVRot = GetActorRotation();

// If our Pitch is 0, then use a replicated view pitch
if( FMath::IsNearlyZero(POVRot.Pitch) )
{
            // use the RemoteViewPitch
            const UWorld* World = GetWorld();
            // Simulated network driver for recording and playing back game sessions
            const UDemoNetDriver* DemoNetDriver = World ? World-&amp;gt;GetDemoNetDriver() : nullptr;
            // This is for replay and recording skip this if statement
            if (DemoNetDriver &amp;amp;&amp;amp; DemoNetDriver-&amp;gt;IsPlaying() &amp;amp;&amp;amp; (DemoNetDriver-&amp;gt;GetPlaybackEngineNetworkProtocolVersion() &amp;lt; FEngineNetworkCustomVersion::PawnRemoteViewPitch))
            {
                POVRot.Pitch = RemoteViewPitch;
                POVRot.Pitch = POVRot.Pitch * 360.0f / 255.0f;
            }
            else
            {
                // This is the main part, we are just assigning Remote View pitch to pitch and returning it
                POVRot.Pitch = FRotator::DecompressAxisFromByte(RemoteViewPitch);
            }
}

return POVRot;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might get a bit overwhelmed at first but most of this code doesn’t even get the chance to execute in normal circumstances because it is for replay and recording features, the thing we are concerned with is the last else of the if else statements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// This is the main part, we are just assigning Remote View pitch to pitch and returning it
POVRot.Pitch = FRotator::DecompressAxisFromByte(RemoteViewPitch);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;variable called &lt;code&gt;RemoteViewPitch&lt;/code&gt; is a replicated member of the class here is how it is declared in the header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UPROPERTY(replicated)
uint8 RemoteViewPitch;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s just a replicated property and another thing that catches the eye is the unsigned integer, in this variable is where our Pitch value is stored in a compressed format.&lt;/p&gt;

&lt;p&gt;We do the compression in the pre-replication stage, pre-replication is a virtual function that you can override, and this is called on classes of type Actors right before the actual replication occurs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void APawn::PreReplication( IRepChangedPropertyTracker &amp;amp; ChangedPropertyTracker )
{
    Super::PreReplication( ChangedPropertyTracker );

    if (GetLocalRole() == ROLE_Authority &amp;amp;&amp;amp; GetController())
    {
        SetRemoteViewPitch(GetController()-&amp;gt;GetControlRotation().Pitch);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;SetRemoteViewPitch&lt;/code&gt; is another function inside the Pawn class which just compresses the float axis value into a single byte.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void APawn::SetRemoteViewPitch(float NewRemoteViewPitch)
{
    // Compress pitch to 1 byte
    RemoteViewPitch = FRotator::CompressAxisToByte(NewRemoteViewPitch);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is all for this topic, I do recommend to go into the pawn class and take a look at these functions again, even if you can’t grasp these fear not as most of time you just will be using the built-in pitch replication for pawns and if you want to compress some other axis the best way to do this is in the pre-replication function.&lt;/p&gt;

&lt;p&gt;Good Luck!&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Move Semantics In Unreal Engine</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 07:18:53 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/move-semantics-in-unreal-engine-40hg</link>
      <guid>https://forem.com/roasted-kaju/move-semantics-in-unreal-engine-40hg</guid>
      <description>&lt;h2&gt;
  
  
  The Copy Problem
&lt;/h2&gt;

&lt;p&gt;In traditional C++ 98 programming you had two ways in which objects were created: From scratch and from copying.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Foo(); // Default Ctor
Foo(int x); // Parameterized Ctor
Foo(const Foo&amp;amp; rhs); // Copy Ctor
Foo&amp;amp; operator=(const Foo&amp;amp; rhs); // Copy Assignment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Copying is usually more processor intensive to overcome this in C++ 11 move semantics were invented.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Foo(Foo&amp;amp;&amp;amp; rhs); // Move Ctor
void operator=(Foo&amp;amp;&amp;amp; rhs); // Move Assignment
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Moving objects is more memory efficient than copying (not every time).&lt;/p&gt;

&lt;h2&gt;
  
  
  When to Implement Special Functions
&lt;/h2&gt;

&lt;p&gt;Deciding for which types to implement custom move constructors basically boils down to following the Rule of Three/Five/Zero, Just ask yourself one question: Does your type deal with ownership? Or, alternatively: Does your type allocate and/or manage (dynamic) resources?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Plain old datatypes&lt;/strong&gt;&lt;br&gt;
For POD types or POD type members, moving is the same as copying. Imagine the difference between adding instances of either of the following two types to a &lt;code&gt;std::vector&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// when added, the pointer to the dynamic memory allocation of numbers can be copied to the new instance in the vector
// sizeof(Foo) = 24 with gcc on Win64
// no reallocation necessary = possible performance gain
struct Foo
{
    // dynamic vector with 1000 entries
    std::vector&amp;lt;int&amp;gt; numbers;
}

// When added, a full copy must be performed
// sizeof(Bar) = 4000 with gcc on Win64
// All 1000 bytes need to be copied
struct Bar
{
    int numbers[1000];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Unreal Engine Terminology
&lt;/h2&gt;

&lt;p&gt;Unreal engine is a bit different when it comes to naming convention and even has some extra functionality&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nuqesh7trbz9ozu7mhh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4nuqesh7trbz9ozu7mhh.jpg" alt=" " width="800" height="169"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Smart pointers are encouraged to be used with not blueprint exposed code whenever it adds clarity and simplifies object lifetime management. The Unreal equivalents to std smart pointers are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TUniquePtr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TSharedPtr&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TWeakPtr&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It’s worth noting that all of this is not usable in the following contexts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;UObjects&lt;/code&gt; cannot be moved or referenced by smart pointers as they are always referenced by pointer and managed by the garbage collector.&lt;/li&gt;
&lt;li&gt;Functions with r-value-reference or smart pointer parameters are not Blueprint exposable.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;UStructs&lt;/code&gt; may define custom move functionality, but rarely benefit from it, because they usually are plain data structs.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Geometry Scripting</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 07:08:29 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/geometry-scripting-5a7c</link>
      <guid>https://forem.com/roasted-kaju/geometry-scripting-5a7c</guid>
      <description>&lt;p&gt;Geometry scripting is much like procedural mesh component, but it comes with alot of handy functions which can make life a lot easier. You can use GS(Geometry scripting) at runtime as well as in editor.&lt;/p&gt;

&lt;p&gt;For runtime you need to use the &lt;code&gt;DynamicMeshActor&lt;/code&gt; and for editor use the Generated dynamic mesh actor.&lt;/p&gt;

&lt;h2&gt;
  
  
  In Editor
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Override the On Generated function.&lt;/li&gt;
&lt;li&gt;Get the target mesh and append box.&lt;/li&gt;
&lt;li&gt;You can use Apply Boolean function as well.&lt;/li&gt;
&lt;li&gt;If you want to make a temporary mesh you can use the Allocate Mesh node
and then append shapes or do anything you like just to make sure to use release all allocated meshes right before the end to do clean up.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Baking Mesh To Static Mesh
&lt;/h2&gt;

&lt;p&gt;You can bake your mesh to a static mesh easily you need a variable of type Static Mesh as public this is where our dynamic mesh will update and write to.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8t4hfaw9kkdatqjztae.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8t4hfaw9kkdatqjztae.jpg" alt=" " width="800" height="534"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the &lt;code&gt;NewMaterials&lt;/code&gt; and &lt;code&gt;NewMaterialSlotNames&lt;/code&gt; in the options this is for, if we want to have multiple slots in our dynamic mesh actor.&lt;/p&gt;

&lt;h2&gt;
  
  
  Material Slots
&lt;/h2&gt;

&lt;p&gt;To have multiple slots on the baked mesh you need to do this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffztibj5jpaqbld3zn2il.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffztibj5jpaqbld3zn2il.jpg" alt=" " width="800" height="362"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use this Remap Material ID node with the &lt;strong&gt;&lt;code&gt;ToMaterialID&lt;/code&gt;&lt;/strong&gt; parameter to which ever slot you like. &lt;/p&gt;

&lt;p&gt;Once that is done you need one more node right before you release the allocated mesh:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F354tjdd79hi9ev46fo5s.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F354tjdd79hi9ev46fo5s.jpg" alt=" " width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Floor and Wall materials here are public variables of type &lt;code&gt;MaterialInterface&lt;/code&gt; which the user can set in editor. &lt;/p&gt;

</description>
      <category>gamedev</category>
    </item>
    <item>
      <title>Visualizer Components</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 06:23:29 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/visualizer-components-1hg6</link>
      <guid>https://forem.com/roasted-kaju/visualizer-components-1hg6</guid>
      <description>&lt;p&gt;Visualizer components are editor only components which helps us draw non-rendering debug information to the screen or HUD, this is more like a modular, lightweight, debug component that does not get shipped with packaged game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating An Editor Module
&lt;/h2&gt;

&lt;p&gt;To Create an editor module, you need to create a new folder with same name as your runtime module but postfix it by “Ed” or “Editor” for example:&lt;br&gt;
Have the following files inside your module folder:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;\Private\CustomModuleEd.cpp
\Public\CustomModuleEd.h
CustomModuleEd.Build.cs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;In your build.cs file:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using UnrealBuildTool;

    public class CustomModuleEd : ModuleRules
    {
         public CustomModuleEd(ReadOnlyTargetRules Target) : base(Target)
         {
               PrivateDependencyModuleNames.AddRange(new string[] 
               {
                   "Core", 
                   "CoreUObject", 
                   "Engine", 
                   "Slate", 
                   "SlateCore", 
                   "UnrealEd", 
                   "ComponentVisualizers"
               });
         }
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And here is how your editor module class should look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    #pragma once
    #include "Modules/ModuleInterface.h"
    #include "Modules/ModuleManager.h"

    class FCustomModuleEd: public IModuleInterface
    {
        public:
        virtual void StartupModule() override;
        virtual void ShutdownModule() override;
    };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include "CustomModuleEd.h"
#include "UnrealEdGlobals.h"
#include "Editor/UnrealEdEngine.h"

IMPLEMENT_GAME_MODULE(FCustomModuleEd, CustomModuleEd);

void FCustomModuleEd::StartupModule() {}
void FCustomModuleEd::ShutdownModule() {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once everything is done you can now add your editor module into your plugin file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "FileVersion": 3,
    ....
    "Modules": [
        {
            "Name": "CustomPlugin",
            "Type": "Runtime",
            "LoadingPhase": "Default"
        },
        {
            "Name": "CustomModuleEd",
            "Type": "Editor",
            "LoadingPhase": "PostEngineInit"
        }
    ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to set the loading phase to &lt;code&gt;PostEngineInit&lt;/code&gt;, in case you want to check if your module is active in editor, you can go here &lt;code&gt;Tools → Debug → Modules&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Component
&lt;/h2&gt;

&lt;p&gt;The way visualization components works is by having a class type usually that is an actor component present outside the editor module that is attached to the actual Actor present inside your levels.&lt;/p&gt;

&lt;p&gt;Hence, we need to create a dummy component inside our Runtime module, we are going to call it debugger component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class MYPROJECT_API UDebuggerComponent : public UActorComponent
{
    GENERATED_BODY()

public: 
    // Sets default values for this component's properties
    UDebuggerComponent();

protected:
    // Called when the game starts
    virtual void BeginPlay() override;

public: 
    // Called every frame
    virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;

public:
    UPROPERTY(EditAnywhere, Category = "Debug")
    float DrawDistance = 1000.0f;

    UPROPERTY(EditAnywhere, Category = "Debug")
    bool ShouldDrawDebugPoints = false;

};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can also add properties, or we can simply read the properties from owning actor, but this component will act as an intermediary between our editor module visualizer and the data which exists inside our run-time module.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add Visualizer Component in Editor Module
&lt;/h2&gt;

&lt;p&gt;Create a new empty class inside the editor module and call it &lt;code&gt;VisualizerComponent&lt;/code&gt; this will inherit from &lt;code&gt;FComponentVisualizer&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/**
 *  Remove the API part of class definition because we don't want to expose this to other modules
 */
class TestVisualizer : public FComponentVisualizer
{
public:
    virtual void DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI) override;

protected:
    AActor* ActorRef; // Reference for actor which needs to show this debug

private:
    FVector PerviousCameraLocation;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void TestVisualizer::DrawVisualization(const UActorComponent* Component, const FSceneView* View, FPrimitiveDrawInterface* PDI)
{
    const UDebuggerComponent* debuggerComp = Cast&amp;lt;UDebuggerComponent&amp;gt;(Component);
    if (!debuggerComp || !debuggerComp-&amp;gt;ShouldDrawDebugPoints) { return; }
        PDI-&amp;gt;DrawPoint(ActorRef-&amp;gt;GetActorLocation(), FLinearColor::Green, 25.0f, SDPG_Foreground);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To make this all work, you need to have your run-time debugger component added onto the actor you wish to have debug visualizers for, you can either do it manually in blueprints, instances or via C++ in constructor using default sub object.&lt;/p&gt;

&lt;h2&gt;
  
  
  Register your Visualizer in Editor Startup
&lt;/h2&gt;

&lt;p&gt;The final step is to register your visualizer component and bind it with the debugger component during the startup function of your editor module.&lt;/p&gt;

&lt;p&gt;Go back to the &lt;code&gt;CustomModuleEd.cpp&lt;/code&gt; and implement the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void FCustomModuleEd::StartupModule()
{
    if (GUnrealEd)
    {
        const TSharedPtr&amp;lt;TestVisualizer &amp;gt; TestViz = MakeShareable(new TestVisualizer ());
        GUnrealEd-&amp;gt;RegisterComponentVisualizer(UDebuggerComponent::StaticClass()-&amp;gt;GetFName(), TestViz);
        TestViz-&amp;gt;OnRegister();
    }
}

void FCustomModuleEd::ShutdownModule()
{
    if (GUnrealEd)
    {
        GUnrealEd-&amp;gt;UnregisterComponentVisualizer(UDebuggerComponent::StaticClass()-&amp;gt;GetFName());
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Compile and launch the editor, once you will select the actor which has the debugger component attached to it, the PDI will draw the debugs you mentioned in &lt;code&gt;DrawVisualization&lt;/code&gt; function inside the class.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>gamedev</category>
    </item>
    <item>
      <title>Concepts In C++ 20</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 00:25:47 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/concepts-in-c-20-4a77</link>
      <guid>https://forem.com/roasted-kaju/concepts-in-c-20-4a77</guid>
      <description>&lt;p&gt;A concept is just a true of false statement, it is like a predicate that returns true or false, there are a number of built in concepts as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
Let's have two templated functions for &lt;code&gt;isEqual&lt;/code&gt; one would be integer specialization and other will be float, for this we will be using built in concepts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt; requires std::integral&amp;lt;T&amp;gt;
bool isEqual(T valueA, T valueB)
{
    std::cout &amp;lt;&amp;lt; "Calling the integral version\n";
    return valueA == valueB;
}

template&amp;lt;typename T&amp;gt; requires std::floating_point&amp;lt;T&amp;gt;
bool isEqual(T valueA, T valueB)
{
    std::cout &amp;lt;&amp;lt; "Calling the float version\n";
    return std::fabs(valueA - valueB) &amp;lt; 0.0001f;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and inside our main driver function we can call these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;std::cout &amp;lt;&amp;lt; std::boolalpha &amp;lt;&amp;lt; isEqual(1, 1) &amp;lt;&amp;lt; std::endl;
// This will work as we have a specialization
std::cout &amp;lt;&amp;lt; std::boolalpha &amp;lt;&amp;lt; isEqual(1.0f, 5.0f) &amp;lt;&amp;lt; std::endl;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lets Make a Custom Concept
&lt;/h2&gt;

&lt;p&gt;Our concept is going to be very simple, as mentioned above concepts are just predicates that return a boolean so we are going to hard code ours to always return true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
concept AlwaysTrue = true;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's use &lt;code&gt;AlwaysTrue&lt;/code&gt; in our templated function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt; requires AlwaysTrue&amp;lt;T&amp;gt;
void printSomething(T value)
{
    std::cout &amp;lt;&amp;lt; value &amp;lt;&amp;lt; std::endl;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In our main driver function:&lt;br&gt;
Since the concept is always true we can pass in pretty much anything.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;printSomething(10);
printSomethingAutoVer("Hello World!");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also combine different concepts using &lt;code&gt;||&lt;/code&gt; operator, so we can make a specialization that takes both integers and floating point values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
concept IsFloatORInt = std::floating_point&amp;lt;T&amp;gt; || std::integral&amp;lt;T&amp;gt;;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Template Specialization Only for Types that have a Push-Back
&lt;/h2&gt;

&lt;p&gt;We want to have a template that only compiles for types that have a push back function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
concept HasPushback = requires(T container, T::value_type valueType) {
    container.push_back(valueType);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since we need to know that we can push a value in the container we are also going to be needing to know the value type that resides in our container, this can be extracted using the &lt;code&gt;value_type&lt;/code&gt;, Now let's make our templated function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt; requires HasPushback&amp;lt;T&amp;gt;
void addIntToContainer(T&amp;amp; container, int integer)
{
    container.push_back(integer);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Concepts are really powerful you can now use the same ideas to do things like make template specializations for types that have a size available at compile time, different specializations for small and big data etc.&lt;/p&gt;

</description>
      <category>cpp</category>
    </item>
    <item>
      <title>Task Based Programming Over Thread Base</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Sat, 07 Mar 2026 00:06:49 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/task-based-programming-over-thread-base-e7e</link>
      <guid>https://forem.com/roasted-kaju/task-based-programming-over-thread-base-e7e</guid>
      <description>&lt;h2&gt;
  
  
  Prefer Task based Programming to Thread-Based
&lt;/h2&gt;

&lt;p&gt;If you want to run something Async you have two basic choices: &lt;code&gt;std::thread&lt;/code&gt; and &lt;code&gt;std::async&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int doAsyncWork();

std::thread th(doAsyncWork);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Better to use Async

auto future = std::async(doAsyncWork);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;std::async(doAsyncWork)&lt;/code&gt; is considered a task. The task is superior because it returns a future value which we can use to sync up our program. Async task also has a get function which we can use to get the status and or if our work function emits an exception.&lt;/p&gt;

&lt;p&gt;Async task also provides more abstraction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the meaning of Thread?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hardware threads, perform computation. Contemporary machine architectures offer one or more hardware threads per CPU core.&lt;/li&gt;
&lt;li&gt;Software threads (also known as OS threads or system threads) are the threads that the operating system manages across all processes and schedules for execution on hardware threads.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;std::threads&lt;/code&gt; are objects in a C++ process that act as handles to underlying software threads.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Software threads are a limited resource. If you try to create more than the system can provide, a &lt;code&gt;std::system_error&lt;/code&gt; exception is thrown. (This is even true for a function that is marked no-except)&lt;/p&gt;

&lt;p&gt;Even if you don’t run out of threads, you can have trouble with oversubscription. That’s when there are more ready-to-run, thread scheduler time-slices the software threads on the hardware. Such context switches increase the overhead.&lt;/p&gt;

&lt;p&gt;Your life would be much easier if you dump all this management to someone else and that someone else is &lt;code&gt;std::async&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Task doesn’t have same problem as Threads.
&lt;/h2&gt;

&lt;p&gt;Well Task would almost never have this out of threads problem because Async task doesn’t guarantee that it will create a new software thread. Rather it permits the scheduler to arrange for the function to be run on thread requesting the &lt;code&gt;doAsyncWork()&lt;/code&gt; result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Launch Policy
&lt;/h2&gt;

&lt;p&gt;async sometimes run on the same thread that is expecting its output, well that is only true if you use the default launch policy which is a combination of both async and deferred.&lt;br&gt;
The behavior depends on the &lt;strong&gt;launch policy&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;std::launch::async&lt;/code&gt; → The function is guaranteed to run on a new thread.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;std::launch::deferred&lt;/code&gt; → The function does not run immediately. Instead, it runs only when you call &lt;code&gt;future.get()&lt;/code&gt; or &lt;code&gt;future.wait()&lt;/code&gt;, and it runs on the same thread that calls &lt;code&gt;get&lt;/code&gt; or &lt;code&gt;wait&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Default (&lt;code&gt;std::launch::async&lt;/code&gt; | &lt;code&gt;std::launch::deferred&lt;/code&gt;) → The implementation decides whether to run it asynchronously (new thread) or deferred (same thread, lazy execution).&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cpp</category>
    </item>
    <item>
      <title>How to Distinguish Universal From R-Value References</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Fri, 06 Mar 2026 23:53:19 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/how-to-distinguish-universal-from-r-value-references-3691</link>
      <guid>https://forem.com/roasted-kaju/how-to-distinguish-universal-from-r-value-references-3691</guid>
      <description>&lt;p&gt;To declare an R-value reference in a template you would usually see something like &lt;code&gt;T&amp;amp;&amp;amp;&lt;/code&gt; it's not that simple, the &lt;code&gt;T&amp;amp;&amp;amp;&lt;/code&gt; has two meanings one is R-value and one is that it can be both R-value and L-value. Furthermore, they can be bound to const and non-const values, volatile and non-volatile and can be bind to virtually anything.&lt;/p&gt;

&lt;p&gt;Universal references arise in two contexts likely in templates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
void func(T&amp;amp;&amp;amp; param);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the second in auto declarations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auto&amp;amp;&amp;amp; var1 = var2;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What both examples above have in common is the presence of type deduction now compare the above two to the examples below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void func(Widget&amp;amp;&amp;amp; param); // R-value
Widget&amp;amp;&amp;amp; var1 = Widget(); // R-value since no type deduction exists
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because universal references are references, they must be initialized, the initializer of the universal reference determines whether it represents R-value or L-value.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
void func(T&amp;amp;&amp;amp; param);

Widget w;
func(w); // since w is an l-value the universal reference will decay to an l-value.

func(std::move(w)) // this time we are first casting 'w' to an r-value then passing it into the template, thus the reference will decay to r-value.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Edge Cases
&lt;/h2&gt;

&lt;p&gt;For a reference to be universal type deduction is necessary, but it's not sufficient the form of reference declaration must also be correct, and that form is quite constrained, it must be precisely “T&amp;amp;&amp;amp;” look at an example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
void func(std::vector&amp;lt;T&amp;gt;&amp;amp;&amp;amp; param); // Parameter is an R-value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The example above will result in a non-universal reference which means it will only take R-values, why you may ask? because there is no &lt;code&gt;T&amp;amp;&amp;amp;&lt;/code&gt;, when function will be invoked the type of just T will be deduced not &lt;code&gt;T&amp;amp;&amp;amp;&lt;/code&gt; as the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; exists with the vector not our template type &lt;code&gt;T&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So, this won’t work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;std::vector&amp;lt;int&amp;gt; vec;
func(vec); // Error, the function will only take R-values.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Even a simple presence of const is enough to disqualify a universal reference.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;typename T&amp;gt;
void func(const T&amp;amp;&amp;amp; param); // Having a const will make parameter an R-value.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Another edge case where this fails is not always being in a template for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;template&amp;lt;class T, class Allocator = allocator&amp;lt;T&amp;gt;&amp;gt;
class vector
{
public:
    void push_back(T&amp;amp;&amp;amp; x);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you might think that push back’s T&amp;amp;&amp;amp; has the right to form a universal reference, but there is no type deduction in this case. This also disqualifies it for being a universal reference.&lt;/p&gt;

</description>
      <category>cpp</category>
    </item>
    <item>
      <title>Special Functions And Pimpl Idiom</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Fri, 06 Mar 2026 23:30:44 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/special-functions-and-pimpl-idiom-54kg</link>
      <guid>https://forem.com/roasted-kaju/special-functions-and-pimpl-idiom-54kg</guid>
      <description>&lt;p&gt;Pointer to implementation is one of the idioms in C++ which dictates that the implementation must be accessed through an indirection, which in simple words mean that we encapsulate all the member data of our class in another struct that we access via a pointer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits
&lt;/h2&gt;

&lt;p&gt;The benefits comes in the form of lowered compilation times, easier to manage headers, the reason compile times decrease is because instead of declaring every member in a header file which than forces us to add headers as well, for example if we have members of type vector and string we will have to include their header files as well and every time we would make a change in those data member types or Let’s say we have another custom type which gets new revisions very often that would result in us recompiling the entire header for our class again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Pointers
&lt;/h2&gt;

&lt;p&gt;Like the name says we hold a pointer to implementation, the pointer can be a raw pointer, unique pointer or a shared pointer.&lt;/p&gt;

&lt;p&gt;Raw and unique pointers are most performance friendly so we will look into those first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pointer
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Header file

class Widget
{
public:
    Widget();
    ~Widget();

private:
    struct Impl; // Also known as forward declaring or incomplete type
    Impl* pImpl; // Pointer to implementation
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Source file
struct Widget::Impl
{
    std::vector&amp;lt;int&amp;gt; m_age;
    std::string m_name;
    PlayerController m_controller; // Our custom type
}

Widget::Widget()
{
    // Constuctor
    pImpl = new Impl();
}

Widget::~Widget()
{
    delete pImpl;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is straight forward, but we are here for smart pointers aren’t we? Let's see how this works with a unique pointer:&lt;/p&gt;

&lt;h2&gt;
  
  
  Unique Pointer
&lt;/h2&gt;

&lt;p&gt;Before we dive into code lets establish some base points regarding pointer to implementation idiom.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It hides private data, so the API remains stable.&lt;/li&gt;
&lt;li&gt;It won’t recompile the header as it just holds a 4 byte (OS dependent) pointer to implementation.&lt;/li&gt;
&lt;li&gt;Downfall is the introduction of an indirection as now you have a pointer.&lt;/li&gt;
&lt;li&gt;Beware while creating a copy constructor.&lt;/li&gt;
&lt;li&gt;This is well used for classes that have huge number of private members.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Header file
class Person
{
public:
    Person(std::string name, std::string address);
    ~Person();

    // Copy operations
    Person(const Person&amp;amp; rhs);
    Person&amp;amp; operator=(const Person&amp;amp; rhs) = delete;

    // Move operations
    Person(Person&amp;amp;&amp;amp; rhs);
    Person&amp;amp; operator=(Person&amp;amp;&amp;amp; rhs) = delete;

    std::string GetAttributes() const;

private:
    struct Impl;
    std::unique_ptr&amp;lt;Impl&amp;gt; pImpl;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Source file
// Always first define the structure where member data is stored
struct Person::Impl
{
    std::string name;
    std::string address;
};

Person::Person(std::name, std::address) : pImpl{std::make_unique&amp;lt;Impl&amp;gt;()}
{
    pImpl-&amp;gt;name = name;
    pImpl-&amp;gt;address = address;
}

Person::~Person() = default;

Person::Person(const Person&amp;amp; rhs)
{
    pImpl = std::make_unique&amp;lt;Impl&amp;gt;();
    pImpl-&amp;gt;name = rhs.pImpl-&amp;gt;name;
    pImpl-&amp;gt;address = rhs.pImpl-&amp;gt;address;
}

Person::Person(Person&amp;amp;&amp;amp; rhs) noexcept
{
    pImpl = std::move(rhs.pImpl);
}

std::string Person::GetAttributes() const
{
    return pImpl-&amp;gt;name + '\t' + pImpl-&amp;gt;address;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A few things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always define the implementation struct before you call the constructors of class else compiler will throw undefined errors because unique pointers don’t work with incomplete types as they needed to be defined along with destructors ahead of usage.&lt;/li&gt;
&lt;li&gt;Remember the special member function generation rules, if you declare a destructor then it will prevent compiler from auto generating the move operations.&lt;/li&gt;
&lt;li&gt;With unique pointer you have to define your own copy constructor else it will do a shallow copy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Shared Pointer
&lt;/h2&gt;

&lt;p&gt;Though using shared pointers is not common but with shared pointers you don’t have a problem with incomplete type neither do you have to custom define any move or copy operation, with shared pointer we will have no effect as they are copyable and moveable by nature.&lt;/p&gt;

</description>
      <category>cpp</category>
    </item>
    <item>
      <title>Null Pointer</title>
      <dc:creator>Haris</dc:creator>
      <pubDate>Fri, 06 Mar 2026 23:22:09 +0000</pubDate>
      <link>https://forem.com/roasted-kaju/null-pointer-j88</link>
      <guid>https://forem.com/roasted-kaju/null-pointer-j88</guid>
      <description>&lt;p&gt;The main reason to use &lt;code&gt;nullptr&lt;/code&gt; over NULL or 0 is that the &lt;code&gt;nullptr&lt;/code&gt; is of type &lt;code&gt;std::nullptr_t&lt;/code&gt; this is very useful in case of function overloading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consider this example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void func(int);

void func(bool);

void func(void*);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now if we call the functions by the following arguments:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;func(0)&lt;/code&gt;   -&amp;gt; This will call &lt;code&gt;func(int)&lt;/code&gt; not &lt;code&gt;func(void*)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;func(NULL)&lt;/code&gt;-&amp;gt; This will also call &lt;code&gt;func(int)&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;So why does NULL also calls func(int)?&lt;/strong&gt;&lt;br&gt;
This is because NULL's possible implementation is: &lt;code&gt;#define NULL 0&lt;/code&gt; Or depending on your compiler in modern C++ version it can be &lt;code&gt;#define NULL nullptr&lt;/code&gt; so just to be on the safe side always use 'nullptr'.&lt;/p&gt;

&lt;p&gt;In case of pointer type &lt;code&gt;(int*)&lt;/code&gt; the compiler correctly deduces the integer 0 to be a null pointer but like above in case of function overloading where a function overload with integer already exists will always overshadow the pointer argument overload.&lt;/p&gt;
&lt;h2&gt;
  
  
  Readability And Clarity
&lt;/h2&gt;

&lt;p&gt;Another important thing that &lt;code&gt;nullptr&lt;/code&gt; does well is readability along with auto keyword, consider this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auto result = findRecord(…);

if(result == 0) {…}

if(result == nullptr) {…}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See how the last statement gives more clarity to the reader that result is of type pointer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fun Fact&lt;/strong&gt;&lt;br&gt;
When you create a new object on heap which is a non-temporary object, however the pointer you get from new is an r-value but it can still point to an l-value.&lt;br&gt;
Dereferencing pointers always create l-value references, notably the object created using new is also an l-value because it has an address.&lt;/p&gt;

</description>
      <category>cpp</category>
    </item>
  </channel>
</rss>
