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"

BindAxis from ACharacter to UObject

On my ACharacter I'm instantiating a new UObject: basicECU = NewObject();

And then I want to bind the axis and actions from the InputComponent to it, so I have: InputComponent->BindAxis("Gas", basicECU, &UBasicECU::Gas); InputComponent->BindAxis("Steer", basicECU, &UBasicECU::Steer); InputComponent->BindAxis("Strafe", basicECU, &UBasicECU::Strafe);

     InputComponent->BindAction("Afterburner", EInputEvent::IE_Pressed, basicECU, &UBasicECU::AfterburnStart);
     InputComponent->BindAction("Afterburner", EInputEvent::IE_Released, basicECU, &UBasicECU::AfterburnStop);
 
     InputComponent->BindAction("RollRight", EInputEvent::IE_Pressed, basicECU, &UBasicECU::RollRight);
     InputComponent->BindAction("RollLeft", EInputEvent::IE_Pressed, basicECU, &UBasicECU::RollLeft);

..But this makes the editor crash as soon as the first bind gets called.

Product Version: UE 4.17
Tags:
more ▼

asked Oct 11 '17 at 07:24 PM in C++ Programming

avatar image

Zarkopafilis
335 32 25 45

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Crash Error would be helpfull. I can only guess here but I assume your Object got garbage Collected. Did you make your UObject a UPROPERTY? Aside from that what does your Object creation exactly look like?

 basicECU = NewObject<UBasicECU>();
more ▼

answered Oct 11 '17 at 09:21 PM

avatar image

Nachtmahr
6.9k 143 24 168

avatar image Zarkopafilis Oct 12 '17 at 03:32 PM

After adding the UPROPERTY() to the header, I get a EXCEPTION_ACCESS_VIOLATION (this was nullptr) whenever other functions try to access the ecu: (Basically fails earlier, when setting up some values, before binding input actions)

 //Declaration on header
 
 protected:
     UPROPERTY(VisibleInstanceOnly)
     UBasicECU * basicECU;

On that function:

 void UBasicECU::SetGear(int Index) {
     selectedGear = Index;
 }

It's declared as

 UCLASS(BlueprintType)
 class OBAN_API UBasicECU : public UObject
 {
 
     GENERATED_BODY()
 
 protected:
     AWhizzingArrowCharacter * pawnRef;
 
     float gasPressure = 0;
     float strafe = 0;
     float steer = 0;
 
     float afterBurnerMultiplier = 1;
     float isCurrentlyRolling = false;
 
     int selectedGear = 1;
     float gears[3] = { 0.1,0,1 };
 
     FRotator normalAlignedRotation;
 
 
 public:
     void SetCharacter(AWhizzingArrowCharacter * pawnRef);
 
     void tick(float ds);
 
     void Gas(float AxisValue);
 
     void Strafe(float AxisValue);
     void Steer(float AxisValue);
 
     void AfterburnStart();
     void AfterburnStop();
 
     void RollLeft();
     void RollRight();
 
     void SetGear(int Index);
 };


(comments are locked)
10|2000 characters needed characters left
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