First of all I have to say that I feel very embarassed for having to post such a noobish question but I’ve been trying for the better part of the last 3 hours to no avail and my deadlines cannot wait.
I have the following code
UGoapAction* ac1 = NewObject<UGoapAction>(); ac1->Name = "A1";
UGoapAction* ac2 = NewObject<UGoapAction>(); ac2->Name = "A2";
UGoapAction* ac3 = NewObject<UGoapAction>(); ac3->Name = "A3";
UHumbleAStarNode* a1 = NewObject<UHumbleAStarNode>(); a1->Initialize(ac1); a1->HCost = 5;
UHumbleAStarNode* a2 = NewObject<UHumbleAStarNode>(); a2->Initialize(ac2); a2->HCost = 1;
UHumbleAStarNode* a3 = NewObject<UHumbleAStarNode>(); a3->Initialize(ac3); a3->HCost = 3;
UHumbleAStarNode const* ca1 = a1;
UHumbleAStarNode const* ca2 = a2;
UHumbleAStarNode const* ca3 = a3;
TArray<UHumbleAStarNode const *> t;
t.Add(ca1); //I've tried with a1 here as well - same error message
t.Add(ca2);
t.Add(ca3);
As you can see I have a TArray which hold elements of type
UHumbleAStarNode const *
so pointers to constant objects.
I’ve defined a “<” operator for this class so the Heapify methods of the TArray can use it.
It’s defined as
bool operator < (UHumbleAStarNode const & rhs) const;
And when I try to Add ca1, ca2, ca3(or a1, a2, a3) to the array I get this error compilation message:
2>D:\Epic Games\UE_4.23\Engine\Source\Runtime\Core\Public\Templates/Sorting.h(38): error C2664: 'bool TLess<UHumbleAStarNode *>::operator ()(const T &,const T &) const': cannot convert argument 1 from 'T' to 'const T &'
2> with
2>
2> T=UHumbleAStarNode *
2> ]
2> and
2>
2> T=UHumbleAStarNode
2> ]
2> and
2>
2> T=UHumbleAStarNode *
2> ]
I’ve tried all variations of pointers and references and constants and I can’t get it to work.
https://forums.unrealengine.com/deve…-exposed-to-bp
This thread mentions that this could happen if I were calling the Add function in a const function, which is not the case.
Any help would be greatly appreciated!
Edit: Okay I wen away for a couple of hours and when I came back and tried recompiling it finally compiled lol. However, I need to use the TArray<UHumbleAStarNode const *> as a priority queue so I tried calling
TArray::Heapify()
on it and unfortunately I’m getting the exact same error.