When is it good to use "MARK_PROPERTY_DIRTY"?

When creating “UFUNCTION” with arrays, the “KismetArrayLibrary.h” uses MARK_PROPERTY_DIRTY on its “DECLARE_FUNCTION”.

I am trying to understand the pattern here, but at the moment I do not know when to apply the concept to my functions. Any idea? What is the reason for use it?

Thanks in advance.

Sincerely, HighRender.

MARK_PROPERTY_DIRTY macro tells the network driver that a value needs to be sent to clients.
This is the PushModel part of the replication system, which allows you to optimize the cost of useless checks for changing the value of variables by timer, which works by default.

Therefore, if you are using a PushModel system, then you need to call this macro every time you change the value of a variable for replication to work.

Thank you for the reply.
However, I have one more question yet.
The variable/parameter that is being marked as dirty is “ArrayProperty” in an “UFUNCTION” that uses Wildcard Arrays. So, the question is: Do I need to use “MARK…DIRTY” only when “changing” the value of the array or when “getting” some of its values too? Please, if you can, tell me some examples when it can be applied or not.

Note 1: I know practically nothing about “PushModel”. First time I’ve been told about this. I’m creating a blueprint function library.

Note 2: I’m at the beginning of my C++ journey using UE. What I don’t find in my advanced research or by “deduction”, I write here on the forum, it may help others in the future as well.

I will be waiting. Thanks in advance.

Sincerely, HighRender.

You only need to mark a variable after changing it, if you just get its current value, no marking is required.

Functions from KismetArrayLibrary receive a reference to the array and modify it directly. Therefore, the variable needs to be marked.
If you pass a parameter to a function by value, then variable marking is not required.

I haven’t found any official documentation about PushModel, but you can read more about it here.

But again, by default Unreal uses an automatic timer that checks for variable changes, so you may not actually need to use variable marking.
Epic themselves have said in some articles that they have not seen significant performance savings from PushModel in their projects, so this system is not used by default.

1 Like

Thank you again.

Perfect explanation. Helped me a lot.
However, I have one last question, so I can mark the topic as resolved.

When you say “parameter by value”, are you referring to something declared like “int32 A”? And parameter by reference would be like “const int32& A”?

And in the end I believe that I will use “Mark…Dirty” in almost all my functions, except 4. Even if it wasn’t necessary, but I will use it more as a “redundancy”, since it doesn’t make much difference in performance like you said (I’ll use it more as a guarantee).

I will be waiting for your response. Thanks in advance.

Sincerely, HighRender.

“Type&”, without “const”
If you declare a variable as constant you will not be able to change its value.

Thank you very much again.
See you!!!

Sincerely, HighRender.