I have custom classes derived from UObject, so i store one of classes in regular type without pointers. But when i try to equate same classes, but different their samples, i get error, that “Operator =(const UItem&) Already declared” So how could i equate one class to another?
UCLASS(BlueprintType)
class UEntity : public UObject
{
GENERATED_BODY()
private:
UItem m_item; //regular item, that i need to change
public:
UFUNCTION(BlueprintCallable)
void test(UItem item) { m_item = item; } //ERROR "Operator =(const UItem&) doesn't fit arguments (UItem)"
};
First, you should use pointers to later call UObjects. You should create UObjects only through Unreal’s functions: NewObject or StaticConstructObject (there are more but these are the basic ones).
This is because they should be managed by Unreal
Second, what you are doing with “void test(UItem item)” is passing the parameters as a copy, which is not good for big sized classes (imagine having to call this func many times and having to do copies every single time…)
What you should be doing is passing them as either a pointer or reference so that no copies are done.
Just to add a bit more to this, if you want to store information such as ItemName, ItemStats, etc, then you don’t need to have a UObject that manages this. Instead you can just have a USTRUCT that has all this information. This is one you can copy and store without using pointers.