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"

Is there a function that instead of "Is in Attack Range Of Player"node?

I'm learning UE4(and C++) through the book "Learning.C++.by.Creating.Games.with.UE4.2015". The book is about UE4.6(or someother version,I'm not sure). My version is 4.10. So there are some compatible promblem.

  1. And one of the problem is there have no node "Is in Attack Range Of Player"(appears in chapter 11,above "Code to swing the sword ").So the question is Which function replaced it ?

  2. AND,Below the "Code to swing the sword " ,there are a function definition :


void AMonster:: SwordSwung()//A function that will be invoked in a blueprints node

{

if(MeleeWeapon) //MeleeWeapon is definition in AMonster as follows"AActor* MeleeWeapon;"

   {  

      MeleeWeapon->Swing();//Here is the problem. VS return an error point that "class 'AActor'  

                                           //has no member Swing()".   

  }  

}


I'm search for the solution in many place. But still don't get the point. This really made me depressed. Hope this time will help! Thanks for everyone for reading here.

Product Version: UE 4.10
Tags:
more ▼

asked May 28 '16 at 12:38 PM in Using UE4

avatar image

iwingn
1 2 3 2

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

2 answers: sort voted first

Thats a expected error.

You have a AActor pointer that should be your Sword. Problems is AActor does not know how to Swing a Sword because the Code inside AActor does not have a Swing() Function.

You can create a class that inherits from AActor say AWeapon and than you can teach this class how to Swing() and istead of pointing to a AActor* you would use AWeapon* (This can point to any weapon or children of AWeapon)

But if you want to use a AActor* and you know you refference a AWeapon Object in there you first have to check if it really is AWeapon or something completly else that inherits from AActor. The only thing your Code know right now is that it can do what a AActor can do.

Here is how you would check if its pointing to a specific Child Type its called Casting.

 AWeapon* TheRealClass= Cast<AWeapon>(MeleeWeapon); //MeleeWeapon is a AActor* we try to Cast it to a AWeapon or ABow or ASomethingElse
 if(TheRealClass != nullptr)
 {
 // The Cast was succesful MeleeWeapon is a AWeapon Type (or something that inherts from AWeapon) and now your Code knows that you can Call TheRealClass->Swing() we can safly call all the things a AWeapon has.
 }
 else
 {
 // Cast failed its a AActor but its not a AWeapon! Dont try to access TheRealClass here.
 }
more ▼

answered May 28 '16 at 02:13 PM

avatar image

Nachtmahr
7k 143 28 172

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

You can find this function in Monster.h file from the ePub files for this book (visit PacktPub.com).

 inline bool isInAttackRange(float d)
 {
     return d < AttackRangeSphere->GetScaledSphereRadius();
 }
more ▼

answered Aug 28 '16 at 06:13 PM

avatar image

hyliganoff
1

(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