x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:https://wiki.unrealengine.com/Render_Target_Lookup

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

Product Version: Not Selected
Tags:
more ▼

asked Feb 04 '15 at 12:58 AM in C++ Programming

avatar image

Avolanty
1 1 3 6

avatar image Moss Feb 04 '15 at 04:25 PM

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.

avatar image Avolanty Feb 04 '15 at 07:46 PM

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?

avatar image Moss Feb 04 '15 at 09:14 PM

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)
 {
 }
 

avatar image Avolanty Feb 04 '15 at 10:57 PM

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

avatar image Avolanty Feb 05 '15 at 01:48 AM

alt text

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?

alt text

avatar image Avolanty Feb 05 '15 at 02:05 AM

"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." -https://forums.unrealengine.com/showthread.php?2428-Access-persistent-current-level-script-from-another-blueprint

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

avatar image Avolanty Feb 05 '15 at 02:11 AM

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.

avatar image Avolanty Feb 04 '15 at 07:53 PM

I am also using 4.6.1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Do you have a constructor defined in your CPP file?

more ▼

answered Feb 04 '15 at 01:00 AM

avatar image

HailstoneRyan
714 40 27 54

avatar image Avolanty Feb 04 '15 at 07:47 PM

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];

}

avatar image Avolanty Feb 04 '15 at 07:50 PM

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.

avatar image Avolanty Feb 05 '15 at 01:51 AM

Made the changes from Moss read upper portion.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question