Download

BP & C++ different results

I wrote a c++ code to remove instances from a Instanced Static Mesh Component but it don’t give the same results as blueprints
The code is made inside a Projectile



BP RESULT

It looks like your C++ code is making the “instances overlapping sphere” call differently.
Trace through it in the debugger to figure out what specific instances it returns, and what data you pass in there.
For example, you’re calling some “ApplyVoxelDamage” function in C++, but using “Remove Instance” directly in the Blueprint. That seems like one place the behavior can diverge.
Also, why are you doing the same thing 8 times in the C++ code? You don’t vary anything based on i in the code you show.

1 Like

The actor that receives the ApplyVoxelDamage has a Instanced Static Mesh and when that function is called on it remove a certain instance
The BP result was made with 8 loops
And this is the BP Result with 2 loops BP RESULT 2 LOOPS
Don’t know why but 8 loops give more accuracy
That’s why in the C++ & BP i loops 8 times

Your C++ version doesn’t actually loop 8 times. In Blueprint both FirstIndex and LastIndex are inclusive, but in the for loop the comparision is < 8 instead of <= 8 making it loop only 7 times since you also start at 1.

1 Like

So i did a LineTrace using my player on c++
then i did the same thing in blueprint and it maybe is because i’m using variables instead
of direct results as i was using in previous blueprint result





Even C++ Code without variables gives the same result

Fixed it


Screenshot_8

That’s just hoping and praying you got it right. That’s not how computers work. Computers are 100% deterministic, and “if it seems to get better, but I don’t know why,” then you MUST STOP and figure out “why.”

everything on a computer can be figured out with the right debugger, and asking the right questions. If you currently are stuck, then take a step back, ask some new questions about bits you don’t understand, and then figure out how to answer those questions.

1 Like

it’s working correctly without the 8 loops