MRCookie
(MRCookie)
1
Hello!
I’m trying to bind some function from UObject-class, like so:
TSharedRef< USomeClass > ptr(new USomeClass ());
SomeDelegate.BindSP(ptr, &USomeClass::SomeFunction);
… but in return i have:
You cannot use TSharedRef with UObjects.
I’ve tried to use TWeakObjectPtr instead of TSharedRef, but I couldn’t find binding method that accepts TWeakObjectPtr . Is there a way to do it?
You should not use new on UObject either, you should use NewObject.
the → and * operators exposes raw pointer, so use *ptr in TWeakObjectPtr
MRCookie
(MRCookie)
3
Well, my plans changed a bit. Now I want to bind function to OnClicked event.
I have “TWeakObjectPtr obj” ready, but when I’m trying to do:
.OnClicked(obj.Get(), &UMyClass::OnButtonClicked)
Error occurs:
You cannot use TSharedPtr or TWeakPtr with UObjects. Consider a UPROPERTY() pointer or TWeakObjectPtr.
You sure that you not trying to contain UObject in TSharedPtr or TWeakPtr anywhere in code? even trying to place it is such argument?
MRCookie
(MRCookie)
5
Solved:
.OnClicked(FOnClicked::CreateUObject(obj, &YMyClass::OnButtonClicked))