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"

Cannot use TSharedPtr with UObjects

I am trying to create a list of available games/servers that a player can join. I was looking at the shooter game example and I was trying to duplicate what they did. However I can't get it to work. First error I got was

 Error    9: error C2039: 'AsShared' : is not a member of 'UArenaFriendsList'

Then I added the following to my class in the header:

 UCLASS()
 class THEARENA_API UArenaFriendsList : public UUserWidget, public TSharedFromThis<UArenaFriendsList>
 {
     GENERATED_BODY()

but when I add TSharedFromThis I got the error:

 Error    2: error C2338: You cannot use TSharedPtr with UObjects.

Anyone know how I could go about showing a list of friends who are currently hosting games. This is the line of code causing all the fuss:

 StartOnlinePrivilegeTask(IOnlineIdentity::FOnGetUserPrivilegeCompleteDelegate::CreateSP(this, &UArenaFriendsList::OnUserCanPlayOnlineJoin));

Product Version: Not Selected
Tags:
more ▼

asked Mar 05 '15 at 03:28 AM in C++ Programming

avatar image

Janyx
487 66 64 211

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

1 answer: sort voted first

The CreateSP on the delegate is "create shared-pointer", and assumes that the object it's being bound to is somehow derived from TSharedFromThis so it can call AsShared() on it.

As the error pointed out, you can't use TSharedPtr with a UObject based type, however we do have a different delegate creation function, CreateUObject, that will work with UObject types.

 StartOnlinePrivilegeTask(IOnlineIdentity::FOnGetUserPrivilegeCompleteDelegate::CreateUObject(this, &UArenaFriendsList::OnUserCanPlayOnlineJoin));

more ▼

answered Mar 05 '15 at 11:18 AM

avatar image

Jamie Dale STAFF
7.4k 176 66 304

avatar image Janyx Mar 05 '15 at 05:10 PM

You're the man!

(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