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"

"Get Player Character" like blueprint?


how can i get my Player Character like i do in blueprints? I'm totaly new to C++ and worked through some basic tutorials. I set up a Variable

 UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = References)
 ASurvivalCharacter* MyCharacter;

in the Headerfile of another class. This is working and a can see the Variable in the blueprint, but how can i get the character in the .cpp file? In blueprints there is a function called "Get Player Character" which can be cast to the specific character class. But i can't find that in c++.

And this is a multiplayer game!

Product Version: Not Selected
more ▼

asked Jul 27 '14 at 02:52 PM in C++ Programming

avatar image

6.8k 333 185 470

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

1 answer: sort voted first

Ok, after googling half of the WWW i found out how to get the character

 for (TActorIterator<AActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
        MyCharacter = Cast<ASurvivalCharacter>(*ActorItr);

MyCharacter is the one i created in the header.

It also works with ->Role to check if its the server or the client. Took me some time to test, but changing a variable on both depending on server or client showed me that it is working (i hope x))

more ▼

answered Jul 27 '14 at 04:28 PM

avatar image

6.8k 333 185 470

avatar image Pierdek Jul 27 '14 at 06:32 PM


This one is cheaper than iterating over all actors.

(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