Home > Net >  'identifier undefined' in C 11 for-loop with USTRUCT
'identifier undefined' in C 11 for-loop with USTRUCT

Time:08-08

I am implementing logging functionality in Unreal Engine 4.27 (in C ). A key part of my code is a function that is called once per game-tick. This function is responsible for iterating over an array of actors that I would like to log data for, checking whether a new log entry should be written at this point in time and calling the necessary functions to do that.

I am iterating over elements of a TArray of UStructs: LogObject->LoggingInfo = TArray<FActorLoggingInformation>. This array is defined as a UProperty of LogObject. In the loop I have to change the values of the elements so I want to work with the original items and "label" the current item as "ActorLoggingInfo". I have seen this done Debugger at run-time

Additional Notes:

1. Something that consistently works for me is omitting the &, using:

for (FActorLoggingInformation ActorLoggingInfo : LogObject->LoggingInfo)

However, this is creating useless duplicates on a per-tick basis and complicates applying changes to the original objects from within in the for-loop, so it is not a viable option.

2. I have also tried auto& instead of FActorLoggingInformation& as used in the examples above, but I encountered the same issue, so I thought it would be best to be as explicit as possible.

I would be very thankful if you had any ideas how I can fix this :) Thanks in advance!

CodePudding user response:

Thanks to Avi Berger for helping me find my problem! In fact, ActorLoggingInfo was actually never undefined and the code within the body of the if-clause was also executed (it just didn't do what it was intended to do).

When stepping through the code in the debugger it never showed the steps within the if-body and ActorLoggingInfo was shown as undefined so when no logs were written, I assumed it was something to do with that instead of my output function not working properly. So lesson learnt, do not blindly trust the debugger :)

  • Related