UCLASS generating errors

Hi all, I got limited programming experience but know enough to debug with many languages. This one on the other hand has me confused with me learning C++ and I cant find any source material to better explain how to resolve the problem. I’m just trying to create a function using a C++ Actor which can then be pulled through a level blueprint and used in my Gerstner wave material to determine the height of an effected object. I found the tutorial on YouTube and I got the waves working but now I’m trying to get the buoyancy part down with the C++ required to make it work.

This only effects my .h

[[[[[Here is the code that does not contain any errors.]]]]]

UCLASS()

class BOUYANCY_API AHeightMapReader : public AActor
{
GENERATED_BODY()

UPROPERTY(Category = HeightMap, EditAnywhere)
UTextureRenderTarget2D* RenderTarget;

UFUNCTION(BlueprintCallable, Category = "HeightMap|Update")
	void UpdateBuffer();

UFUNCTION(BlueprintCallable, Category = "HeightMap|Texture Helper")
	FColor GetRenderTargetValue(float x, float y);

private:

TArray<FColor> ColorBuffer;

};

[[[[[Here is the code with the errors 18 to be exact.]]]]]

UCLASS()

class BOUYANCY_API AHeightMapReader : public AActor
{
GENERATED_UCLASS_BODY()

UPROPERTY(Category = HeightMap, EditAnywhere)
UTextureRenderTarget2D* RenderTarget;

UFUNCTION(BlueprintCallable, Category = "HeightMap|Update")
	void UpdateBuffer();

UFUNCTION(BlueprintCallable, Category = "HeightMap|Texture Helper")
	FColor GetRenderTargetValue(float x, float y);

private:

TArray<FColor> ColorBuffer;

};

The UCLASS is the only change that causes the errors, why is that?

I also cant seem to pull the function UpdateBuffer in my level blueprint. For some reason other people can use UCLASS without error so why is mine the case? Here is the link for the Tutorial:A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

Here is the first Error I get Error 1 error LNK2019: unresolved external symbol “public: __cdecl AHeightMapReader::AHeightMapReader(class FObjectInitializer const &)” (??0AHeightMapReader@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function “public: static void __cdecl AHeightMapReader::__DefaultConstructor(class FObjectInitializer const &)” (?__DefaultConstructor@AHeightMapReader@@SAXAEBVFObjectInitializer@@@Z) E:\UNREAL4\Unreal Projects\GunsBackup2\Bouyancy\Intermediate\ProjectFiles\HeightMapReader.cpp.obj Bouyancy

Do you have a constructor defined in your CPP file?

Why are you using GENERATED_UCLASS_BODY? You shoudl use GENERATED_BODY from 4.6+, and that’s what seams to work fine in your case. Using GENERATED_UCLASS_BODY will require you to create the FObjectInitializer ctor.

Oh so the GENERATED_UCLASS_BODY is dependent on the version. OK then why cant I seem to pull this through blueprint? Do I need to insert an FObjectInitializer for this to work?

Here is my CPP file for review.

void AHeightMapReader::UpdateBuffer()
{
ColorBuffer.Reset();

if (RenderTarget != NULL)
{
	FTextureRenderTarget2DResource* textureResource = (FTextureRenderTarget2DResource*)RenderTarget->Resource;
	if (textureResource->ReadPixels(ColorBuffer))
	{

	}

}

}

FColor AHeightMapReader::GetRenderTargetValue(float x, float y)
{
float size = 10000;

if (RenderTarget == NULL || ColorBuffer.Num() == 0)
	return FColor(0);

float width = RenderTarget->GetSurfaceWidth();
float height = RenderTarget->GetSurfaceHeight();

//Convert coordinates to texture space
float normalizedX = (x / size) + 0.5f;
float normalizedY = (y / size) + 0.5f;

int i = (int)(normalizedX * width);
int j = (int)(normalizedY * height);

if (i < 0) i = 0;
if (i >= width) i = width - 1;
if (j < 0) j = 0;
if (j >= height) j = height - 1;

int index = i + j * width;
if (index < 0) index = 0;
if (index >= ColorBuffer.Num()) index = ColorBuffer.Num();

return ColorBuffer[index];

}

Is there a new change for me to insert something into the script for it to work in the new version? This CPP is also not my main CPP its the CPP for the actor I created.

I am also using 4.6.1

This is a sample base class with all the required stuff:

//
// MyActor.h
//

#pragma once
#include "MyActor.generated.h"

UCLASS(Config = Game, BlueprintType, Blueprintable)
class AMyActor : public AActor
{
	GENERATED_BODY()

public:
	AMyActor(const FObjectInitializer& ObjectInitializer);
}

//
// MyActor.cpp
//

#include "ProjectMain.h"
#include "MyActor.h"

AMyActor::AMyActor(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

Oh ok, I’ll five this a shot and ill get back with you shortly.

28996-dynamicheightmaplevelblueprint.png

OK so the dynamicheightmaplevelbluprint.png shows what needs to happen with something about persistent level.

The other picture myheightmap shows what I have. Not sure how to make it work as it should. I also added the code you suggested with the necessary changes. Is there something I have to do to make my UpdateBuffer() function public? Do I have to cast? How do i make it Persistent?

Made the changes from Moss read upper portion.

“You are not allows to directly reference the Level Blueprint from inside a Class Blueprint. This would prevent you from using it in different maps. Instead I think you want to use an Event Dispatcher.” -Access persistent/current level script from another blueprint - Blueprint - Unreal Engine Forums

Hmm I’m going to try this method to see if I can get the persistent level.

Oh I’m dumb lol, I have to continue more of the tutorial to get this correct. Thanks for your help guys in getting me situated. I’ll check back sometime to let you know if it was successful, but at this point the issue of the UCLASS has been resolved. It was due to the version between 4.5 to 4.6 and me just not setting up the actor to be read public so the blueprint could call it.