It’s a struct. Just declare it on the stack: FStatus EntangleS;. Default subobjects are for constructors and UObjects.
AddStatus should take a const & input. Just best practice, should actually cause you problems.
AddStatus - So you check if the status is already present, if it is you update it. If it’s not, you log errors? You then call another function with only the name of the status effect. We can’t see what ApplyStatusEffect is doing, but it can’t be adding the FStatus to your array. How would any effect be added the first time? Why is adding an effect that doesn’t already exist an error? That seems like the thing that will happen most of the time. At no point (in the code you’ve shared at least) is it possible for an FStatus to be added to that array because the first instance will always fail the contains check.
Don’t do contains + find. Just do Find and check the return value to know if the index is within the array. Imagine you have 1,000,000 status effects. Contains could check every million elements and then find is going to repeat the exact same checks.
What’s the type of Status in Status.Find(NewStatus, ID) and Status.Add(NewStatus)?
Is it a pure TArray<FSatus> or is it custom class? Can you log the size of it after adding?
Make sure Status.Add(NewStatus)actually copies the properFSatus data in your container. I think @MagForceSeven is right to suspect that the effect is not actually added for some reason.
Try to debug the raw content of Status container after an addition. If it looks alright (like expanding), that means that the reading/application is failing.
(Also do all the things @MagForceSeven pointed out. I think EntangleS declaration is commented out.)
Have you stepped through this code with your IDE? Maybe you’re adding to one manager but the ‘get’ that’s empty is reading from a different one. Maybe something is removing it between the add and get.
Unfortunately I don’t think there’s anything anyone without access to your full project would be able to do to help you out (no I’m not asking for that sort of access). You’re going to have to debug it with breakpoints and perhaps more logs. What you’ve shared should work just fine (though my other pieces of feedback are still relevant for making it better).
Totally unrelated, but having something called “ErrorManager” handling things that aren’t errors is very unintuitive.
Ok, I made some more testing and I managed to get the variables of the struct in another part of the code and the system that does the auto removal of expired status seem to be working. So now the question is, why I’m not being able to read this variables in some parts of the code
Also, the ErrorManager is something that I inherited from the previous programmer, so it was not my choice
Ok, I think I found the problem.
The ErrorManager seemingly can’t read integers and one of the functions that I was trying to use the StatusManager in, wasn’t being used