Temporarily save the result of allVertexGridNodes and then filter:
auto gridNodes = allVertexGridNodes();
auto filteredResult = gridNodes.FilterByPredicate([]() {});
Chain using allVertexGridNodes and filter:
auto filteredResult = allVertexGridNodes().FilterByPredicate([]() {});
These 2 cases give me different results. Is this by design?
Expected Result
Case 1 should be equal to case 2 in all aspects.
Phenomenon in Detail
In case 1, filteredResult is an array as expected.
In case 2, filteredResult is also an array with the same number of elements as case 1, but there is always one invalid element in this array. The values in this invalid element are unpredictable, like a pointer with all its properties released.
Environment
Unreal Engine 5.4
Things Tried
In Unreal Engine 5.4’s source code, it’s 100% reproducible on my PC.
I’ve tried some simple cases in a C+±only context without using UE in VS Code, using only std::vector and std::shared_ptr, but failed to reproduce this issue.
Using a plain old for loop in the code below gives the same result, so it’s not an issue with Algo.
I should copy all the TArray related code to C++ to try to reproduce this in VS Code, but I’m overwhelmed by C++. The memory management of TArray seems incomprehensible to me as a junior C++ learner.
I really want to use chaining in C++, just like in some other languages. (Not using chaining in this case seems verbose to me.)
hi ,
could you try reference assigment like this and check the results:
auto gridNodes { allVertexGridNodes()};
auto filteredResult { gridNodes.FilterByPredicate( {})};
auto filteredResult2 { allVertexGridNodes().FilterByPredicate( {}) };
Your suggestion is accepted and tested.
Here is the result.(Only testing the last one,since case 1 is an OK for me)
Please feel free to ask for more , if you want more info or tests!
TLDR(joking)
Reference Assignment works.
But plain chaining without reference assignment keeps giving incredible result.