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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to drag TargetPoint to the panel?

Hello,

I don't understand why does the complier not allow me to put object of TargetPoint in a TArray.

This is my code:

 #include "CoreMinimal.h"
 #include "AIController.h"
 #include "GuardAIController.generated.h"
 
 /**
  * 
  */
 class ATargetPoint;
 UCLASS()
 class FPSGAME_API AGuardAIController : public AAIController
 {
     GENERATED_BODY()
 
 public:
     AGuardAIController();
 
     void OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& Result) override;
     
 protected:
     void BeginPlay() override;
 
 private:
     UPROPERTY(EditDefaultsOnly, Category = "TargetPoints")
     TArray<ATargetPoint> TargetPoints;
 
     int CurrentTarget;
     ATargetPoint* GetNextPoint();
 
     void WalkToNextPoint();
 };

and cpp:

 #include "GuardAIController.h"
 #include "Engine/TargetPoint.h"
 
 AGuardAIController::AGuardAIController() 
 {
 
 }
 
 void AGuardAIController::OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult & Result)
 {
     Super::OnMoveCompleted(RequestID, Result);
     WalkToNextPoint();
 }
 
 void AGuardAIController::BeginPlay()
 {
     CurrentTarget = -1;
     WalkToNextPoint();
 }
 
 ATargetPoint* AGuardAIController::AGuardAIController::GetNextPoint()
 {
     if (CurrentTarget + 1 < TargetPoints.Num()) {
         CurrentTarget = CurrentTarget + 1;
         return &TargetPoints[CurrentTarget + 1];
     }
     else {
         CurrentTarget = 0;
         return &TargetPoints[0];
     }
 }
 
 void AGuardAIController::WalkToNextPoint()
 {
     MoveToActor(Cast<AActor>(GetNextPoint()));
 }

In general, I just want to make my character walk through each targetPoint. Now I face a problem. I don't know how can I drag on target points into the slot of the editor. At the beginning, I use type "ATargetPoint*" instead of "ATargetPoint" for my TArray. I can complie it successfully and the slots shown on the pannel, However, After putting the target points into the slots, they are still showing "None". I think may the slot is for type TargetPoint* but not TargetPoint? So I change the TArray to TArray. However, This time I just can't complie the program.

I am new to C++ and Unreal. I really appreciate any help.

Product Version: UE 4.22
Tags:
more ▼

asked May 21 '19 at 12:36 AM in Using UE4

avatar image

TBWorkss
3 1 1

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

1 answer: sort voted first

Using a pointer is the right way to do it, you should however close the editor and rebuild the solution from Visual Studio (or whichever IDE/Compiler you use)

Changing UProperties is extremely buggy with hot reload and I've had many issues running into null pointers (None) while using hot reload, which I eventually stopped using completely because it simply sucks too much.

You also seem to have a syntax error in line 21 of the cpp ( ATargetPoint* AGuardAIController::AGuardAIController::GetNextPoint())

And also just as a sidenote the upcasting you're doing on line 34 of the cpp isn't necessary (`MoveToActor(Cast(GetNextPoint()));`), if your ATargetPoint is an actor (which it probably is since it starts with A) then the cast will always succeed and isn't necessary since ATargetPoint already is an Actor, and if it isn't an actor then the cast is going to return a nullptr and not warn you or anything.

Edit: I just talked that at some point no matter what I tried to do it was still not working and the "None"s persisted, what I suggest at this point if this happens to you is to make a new blueprint completely and derivate it from the same base cpp class, copy everything you had changed on it and then remove the old one completely, it was the only way I found after the blueprint was already corrupted sadly, if you know if any other way please do share it!

I really hope all of these blueprint corruption issues get fixed soon...

more ▼

answered May 21 '19 at 07:47 AM

avatar image

Chkoupinator
132 1 5 4

avatar image TBWorkss May 21 '19 at 04:58 PM

Thank you very much. I rebuild my project through my Visual Studio. But I still face the same problem. I upload a fig. "无" means "None".alt text. Do you have any ideas?

cannotdrag.gif (671.8 kB)
avatar image Chkoupinator May 21 '19 at 05:04 PM

Oh yeah, at some point no matter what I tried to do it was still not working and the "None"s persisted, what I suggest at this point is to make a new blueprint completely and derivate it from the same base cpp class, copy everything you had changed on it and then remove the old one completely, it was the only way I found after the blueprint was already corrupted sadly.

I will edit the main post and add this part to it, please keep me updated and if this solves your problem please consider marking the issue as resolved!

avatar image TBWorkss May 21 '19 at 06:40 PM

Ah, It still doesn't work...

(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