Created Damage Type object automatically garbage collected, right?

So I’m using Damage Types (DT)… Everything works 100% fine when it comes to applying damage and processing the damage type on hit. I cast the object to my custom DT class, and I use the functions to get the appropriate data. Works great.

However, when I want to query info from the damage types outside of this (i.e. in my weapon tooltips, I want to show the specific info from the DT. The problem is, you can’t get info directly from the class, unless it’s an object.

2 part question:

1> Is what I’m doing here a “proper” way to handle this? Is there a better way to deal with this type of thing for getting data from these classes? Setting the pointer to NULL should flag it for garbage collection, correct?

2> I considered just ditching the ApplyDamage and DamageType systems and making my own… but I’m curious if they are worth keeping since they are part of the engine and possibly faster/better than anything I would make myself (especially for multiplayer.) (I also want to note: I’ve looked at GAS, and I’m not interested in it at all - I know someone is going to tell me to look at it :slight_smile: )

Thanks!

You’re doing all of this in a function which releases from memory on return. If DT is a function local var, then it’ll clear on return.

That was my assumption too, but after witnessing function outputs not clearing in memory when you access the function a 2nd time, I figured it is better safe than sorry to manually clear the locals as well.

But my question still stands: is creating an object and then releasing it a proper way to deal with Damage Types if you need info from them?

Output values are exempt because they are being stored outside the functions temp memory.

Data Obj created and fully contained in the function should clear on function return. If you output a copy of the obj it will persist, but not in the function itself. Outputs are copies.

Hi, you can use GetClassDefaults node to get default variable values, you don’t need to create an actual object:

To answer your second question, this is very common approach to create your own damage system. It will be much more fitted to your needs. But rather consider it only if you want to do something more advanced, for basic stuff you can handle it with built in system.

And I’m also not a fan of GAS, there are many issues with them, especially in multiplier.

I use DataAssets myself, the PrimaryDataAsset is already instantiated and can handle logic while the DataAssets hold the DamageType etc

The problem with that, is you can only grab variables. I don’t like the idea of having an external object directly accessing data that should be private, especially since the DT holds an array of structs (which IMO is the worst combo to let some other BP access externally. IMO you should always just output specific data that the user-object requested.)

To answer your second question, this is very common approach to create your own damage system. It will be much more fitted to your needs. But rather consider it only if you want to do something more advanced, for basic stuff you can handle it with built in system.

And I’m also not a fan of GAS, there are many issues with them, especially in multiplier.

Thanks, appreciate the input. I originally was going to do a custom system, but I found a decent method to deal with DTs when passing in custom resists. It seems to work fine, although the only downside is you have to create a child DT for every combination of resists you want, as opposed to a custom system that might have manually set resists per weapon (instead of per generic damage type.)

Either way, I’m either creating a bunch of re-usable DT types, or I’m manually setting all the resists inside every weapon itemType. I think the re-usable DTs might be smarter, cause a lot of weapons might share the same resist “profiles” anyway. But I’ll have to see if this holds up long-term.

The screenshot I posted is a function inside of a PDA for my item types. But the DT inside the data asset needed to be a class, because that’s what is passed into the ApplyDamage function.

I would think the lesser of 2 evils would be to store the class, and then create the object temporarily and garbage collect it. Instead of saving a DT object inside every data asset? Or am I wrong?

OK, this is probably the answer to my main question then. I just wanted to make sure there weren’t any weird known bugs with BP functions that let these objects pile up and eat memory. And unfortunately there didn’t seem to be a manual function to delete the object immediately. You have to just “hope” the garbage collection works (which I hate relying on as a programmer.)

Going to wait a bit and see if anyone else has input on different methods of handling DamageTypes.

Rev is correct if thats your only question, you can also MarkAsGarbage() in c++

its obviously a tried and tested method since its built into base unreal so you dont need to worry.

but as an alternative i just prefer to create my own systems. i use ActorComponents instead of the DamageEvent, Data assets instead of Tables.

you could even have all your damage types directly inside the AC and use an Enum to switch.
but all methods work