UPROPERTY-able class, how can I create one?

I’m trying to create a very simple helper class that I can use as a serializable/replicatable UPROPERTY in an actor class, but as soon as I add the UPROPERTY() attribute, I receive the error:

> error : In Town: Unrecognized type ‘FCapacity’
1>Error : Failed to generate code for MyGameEditor - error code: 4

This is the code:

#include "Tickable.h"

class FCapacity : public FTickableGameObject
	INT32 Amount;
	INT32 Max;

	virtual void Tick(float DeltaTime) OVERRIDE;
	virtual bool IsTickable() const OVERRIDE;
	virtual TStatId GetStatId() const OVERRIDE;


#include "GameFramework/Actor.h"
#include "Capacity.h"
#include "Town.generated.h"

class ATown : public AActor

	FCapacity FoodCapacity;

I haven’t been successful in finding documentation for requirements of creating UPROPERTY-able types, any help is appreciated.


Why do you need UPROPERTY()?

is it just for garbage collection protection?

I dont think your class will get GC’ed unless it is up to the UObject subsystem level.

I am not sure what the best design approach is here.

You could make UFUNCTION() accesors to the non UPROPERTY data,

and replicated vars and functions that set the values of the non UPROPERTY() class.

I can’t see how to do this without setting up a structure around the non-UPROPERTY() class.

I am sure Epic can help more with this :wink:

I am hoping to make it available to blueprint editing and for replication, is this possible without UPROPERTY?

Thanks for the response Rama (and for all of the Wiki contributions you’ve made btw, they’ve been greatly helpful),

I’d be happy to know how the FVector class can be made into a UPROPERTY, and how I can achieve similar results, I think.

From what I can tell, there isn’t much special going on in the class itself that makes this possible, but then, what external step would I need to do to expose my custom class in the same way?

You’re welcome!

Well FVector is quite the core class so it’s surely getting lets of special treatment

Let’s see what Epic has to say!


Did you ever find a solution to this, I’m trying to do basically the same thing. UObject* Var UPROPERTY variables are not editable in the Editor Defaults - Programming & Scripting - Unreal Engine Forums

I have been using structs in combination with blueprint library classes (defined in c++), as opposed to c++ classes to do this kind of thing. It’s irksome to stray from classes and methods, but I’m afraid I’ve found no better way to expose functionality and configurability to blueprint.

I actually found how to edit the u objects variables in the editor. You have to click the down arrow in the dropdow, then at the top is an Edit that will open up a new properties window containing all the UObjects variables defaults to edit.

Mark your FCapacity class as USTRUCT() with GENERATED_USTRUCT_BODY() macro inside (similar to how you would do it for UObject derived). Then you should be able to use it with UPROPERTY.

Thanks ttvd,

That is indeed the way I have been dealing with these scenarios (with ustructs in conjunction with blueprint function libraries), though this question was in regards to using classes (with methods) like we can use Structs.

Since this is not possible (as far as I now know), I will mark this as the correct response.