Shader in C++ with 4.19

I try to make VERY SIMPLE sample project on using HLSL files with C++. I follow this link:

and make everything sorted, but got compiler issue:

3>D:\18T2\GPG\week 08\Sh01\Source\Sh01\Private\Shader01.cpp(11): error C2039: 'ShouldCompilePermutation': is not a member of 'AShader01::FMyTestVS'

Please if you can fix this, please help ….

I made an empty project in editor, then copy HlSL file as tut said in folders, and here is my class:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Runtime/ShaderCore/Public/GlobalShader.h"
#include "Shader01.generated.h"

UCLASS()
class SH01_API AShader01 : public AActor
{
	GENERATED_BODY()
	
public:	
	AShader01();

protected:
	virtual void BeginPlay() override;

public:	
	virtual void Tick(float DeltaTime) override;

class FMyTestVS : public FGlobalShader
{
	DECLARE_EXPORTED_SHADER_TYPE(FMyTestVS, Global, /*MYMODULE_API*/);

	FMyTestVS() { }
	FMyTestVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer) {
	}
	static bool ShouldCache(EShaderPlatform Platform)
	{
		return true;
	}
};

.cpp file

#include "Shader01.h"

AShader01::AShader01()
{
	PrimaryActorTick.bCanEverTick = true;
	IMPLEMENT_SHADER_TYPE(, FMyTestVS, TEXT("/Engine/Private/MyTest.usf"), TEXT("MainVS"), SF_Vertex);

}

void AShader01::BeginPlay()
{
	Super::BeginPlay();
}

void AShader01::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

…not sure how to fix this … please help if you can …

Cheers

You paste it wrong

-First of all you don’t need actor class for this.

-You declered FMyTestVS inside AShader01 which is probably main cause of a error, move it outside of that class

-You need to place IMPLEMENT_SHADER_TYPE outside of the constructor or any other function

Many thanks for your message … ; ] , .
I change my .h class to this

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Runtime/ShaderCore/Public/GlobalShader.h"
#include "Shader01.generated.h"

UCLASS()
class SH01_API AShader01 : public AActor
{
	GENERATED_BODY()
	
public:	
	AShader01();

protected:
	virtual void BeginPlay() override;

public:	
	virtual void Tick(float DeltaTime) override;
	
};

class FMyTestVS : public FGlobalShader
{
	DECLARE_EXPORTED_SHADER_TYPE(FMyTestVS, Global, /*MYMODULE_API*/);

	FMyTestVS() { }
	FMyTestVS(const ShaderMetaType::CompiledShaderInitializerType& Initializer) : FGlobalShader(Initializer) {
	}

	static bool ShouldCache(EShaderPlatform Platform)
	{
		return true;
	}

};

and then comment this l,line on .cpp file

IMPLEMENT_SHADER_TYPE(, FMyTestVS, TEXT("/Engine/Private/MyTest.usf"), TEXT("MainVS"), SF_Vertex);

And when i compile, i have NO issue. Then I try it this way, as you pointed to , and it is NOT working …

#include "Shader01.h"

IMPLEMENT_SHADER_TYPE(, FMyTestVS, TEXT("/Engine/Private/MyTest.usf"), TEXT("MainVS"), SF_Vertex);
// Sets default values
AShader01::AShader01()
{
	PrimaryActorTick.bCanEverTick = true;

}

….

and also typed at the end of this file … but no luck

error message:

3>E:\officeue\18T2\GPG\week 08\temp\Source\Sh01\Private\Shader01.cpp(5): error C2039: 'ShouldCompilePermutation': is not a member of 'FMyTestVS'
3>E:\officeue\18T2\GPG\week 08\temp\Source\Sh01\Public\Shader01.h(29): note: see declaration of 'FMyTestVS'
3>E:\officeue\18T2\GPG\week 08\temp\Source\Sh01\Private\Shader01.cpp(5): error C2065: 'ShouldCompilePermutation': undeclared identifier

… what is wrong here? …