I am wondering about the performance of a code snipped that I have in C++ vs BP. I use it to change the location of an actor when the mouse moves along the y axis.
I know that the function GetAllActorsOfClass ([defined here][2]) is rather slow but besides that, the outcome is different in BP and C++.
When I use the BP implementation, setting the actor location is very smooth and the actor moves with the mouse up and down. When using the C++ implementation, changing the location is not smooth but lags a bit and sometimes stops.
Am I missing something here? I wanted to implement everything in C++ so that I do not have to expose variables and stuff.
Well the big difference between the two is that the C++ is looping over every actor returned by GetAllActorsOfClass and the BP version only does the first element. So perhaps there are more being returned on the C++ side than you think there should be. I’d change either the BP to have the same forloop or remove the loop from the C++ side and see if you don’t get the same behavior both places after that.
Technically the abs() call in your C++ code should be fabs() but I can’t see that making any diff in performance. I would guess that perhaps you have some other differences between the two environments outside of this one particular function.