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"

How do I create a variable in C++ that stores a specific character? or accesses a specific character?

For instance, I want to create an enemy that only targets one specific character on screen. Right now I have the enemy walking towards the location of the player character using

ACharacter* MainCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);

and manipulating the Maincharacter stuff, but when I switch to a different playable character, now they start to target that character. I know why it does this, because it gets 0 on the player index and when I switch to the other character he is still player 0 index.

What I would like is to create a reference to main character of the game, and then when I switch to the second character, the enemy will still target that main character because they're doing logic only with the reference of the main character.

In blueprint you solve this by doing a cast. Now I have very little knowledge how to use this correctly and I'd like an idea of how to do so.

I have ACharacter_Main and ACharacter_Partner and ACharacter_Enemy if that helps..

Product Version: Not Selected
Tags:
more ▼

asked Jan 04 '15 at 04:06 AM in C++ Programming

avatar image

Demoneyejin
95 12 16 27

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

1 answer: sort voted first

Hey Demoneyejin

Why not store a pointer to the character you want the enemy to target? Say in the game mode? You could initialize it with the UGameplayStatics function, but thereafter it just sits in the game mode and the enemy makes a call to the game mode to get it? Thats if you're spawning new enemies- otherwise you could probably store the pointer as a data member of the AI? You could make it private and have getter and setter functions in the AI.

more ▼

answered Jan 04 '15 at 01:42 PM

avatar image

robbiecooper
766 79 60 235

(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