0

C++ and Unreal newbie here. I have a class with a function I'm calling from a Blueprint. I want to create an array of floats (converted from a string) and push a value from Blueprint to it, but I'm getting an error I don't quite understand.

I'm declaring the array like this in my header file:

private:
    TArray<float> SensorValues[5];

Then I try to push a value from my Blueprint in the cpp file:

void Test::UpdateSensor(FString SensorValue)
{
    float sensorVal = FCString::Atof(*SensorValue);
    SensorValues.Push(sensorVal);
}

Which results in this error:

   error C2228: left of '.Push' must have class/struct/union

Any guidance?

Andrew Langley
  • 41
  • 1
  • 10
  • `TArray SensorValues[5];` declares a raw array of 5 `TArray` instances. Raw arrays do not provide any member functions, hence the error message. – πάντα ῥεῖ Sep 03 '18 at 23:32
  • So what should it look like? Originally I had this as the declaration in the header, but it gives the same compiler error: TArray SensorValues; Does that still result in a raw array? If so, why? – Andrew Langley Sep 04 '18 at 00:05
  • `TArray SensorValues;` doesn't result in a raw array. – πάντα ῥεῖ Sep 04 '18 at 00:09
  • But if I do that, it still results in the same compiler error when I try to push to it. error C2228: left of '.Push' must have class/struct/union – Andrew Langley Sep 04 '18 at 00:19
  • The code appears confused on the type of SensorValues. Does the TArray type have a method called Push? If so you need to pick a specific element in the SensorValues array like SensorValues[1].Push(sensorVal); – Matthew Fisher Sep 04 '18 at 00:31
  • Trying to index it like you suggested gives more errors, since it's not a valid element. TArray does have a Push method as far as I can tell. – Andrew Langley Sep 04 '18 at 00:47

2 Answers2

0

I think you forgot to include the header :D

buRn
  • 66
  • 3
0

According to documentation TArray is dynamic array, so you should have tried

private: TArray<float> SensorValues;

besides

private: TArray<float> SensorValues[5];

Hayra
  • 456
  • 2
  • 7
  • 22