[Original tutorial is based on UE 4.18, MINE is based on UE 4.25]

English original Address

In the last section, you need to do three things to completely hide your character in the game.

  • You have to disable its collision,
  • Disable its click,
  • Hide it in the game.

You can add code to any actor subclass instance. For this example, I created a separate actor to demonstrate its use.

Create an actor named HideActor. In the header file I created two: trace through bool HideInGame if we want to DisableActor, and run all the elements we need to disable in void DisableActor. We place these two variables in the Disable category to distinguish them from other properties of actor

HideActor.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "HideActor.generated.h"

UCLASS(a)class UNREALCPP_API AHideActor : public AActor
{
	GENERATED_BODY(a)protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay(a) override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere, Category = "Disable")
	bool HideInGame;

	UFUNCTION(BlueprintCallable, Category = "Disable")
	void DisableActor(bool toHide);
	
};
Copy the code

In BeginPlay(), we check to see if the HideInGame is true. If true, run DisableActor(). DisableActor() Hides the actor, disables it for conflict, and disables it for running each frame.

HideActor.cpp

#include "HideActor.h"

// Called when the game starts or when spawned
void AHideActor::BeginPlay(a)
{
	Super::BeginPlay(a);if (HideInGame)
	{ 
		DisableActor(HideInGame); }}// Called every frame
void AHideActor::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

void AHideActor::DisableActor(bool toHide) 
{
	// Hides visible components
	SetActorHiddenInGame(toHide);

	// Disables collision components
	SetActorEnableCollision(false);

	// Stops the Actor from ticking
	SetActorTickEnabled(false);
}
Copy the code

Results demonstrate

Cube components have been added for actors for demonstration purposes

 

Run the Game when Hide In Game is false

 

Run the Game when Hide In Game is true