Download

What does UFUNCTION() and UPROPERTY() without any arguments do?

In general I have a idea that UFUNCTION() and UPROPERTY() exposes the function and variables that follow respectively to unreal reflection System.

The most Important use of these I know is Exposing them to blueprints and making network architecture for game.

But what if I don’t write anything in the Parentheses what will it do then? Is it useful to mark every variable and function?

In short what is the difference and use of following



UFUNCTION()
void foo()

UPROPERTY()
int bar;


Over



UFUNCTION(BlueprintCallable or Server etc)
void foo()

UPROPERTY(EditDefaultsOnly or something else)
int bar;

2 Likes

I think one of the reasons are that all macro defined elements in your code will be recognized by UE´s garbage collection, as you may know c++ doesnt come with a
garbage collector.

edit: means if you place UBlahblahblah above a variable(Probably pointertype) it will be garbage collected in case its unreferenced. Dont think you would put one over primitives though

What about funtions

I believe functions need to be marked as UFUNCTIONS for them to be able to be used with timers and delegates.

2 Likes

hey, yes thats right, means you dont need to provide UFUNCTION() for functions that wont be used in some of unreals magic but for example if
you make a Timeline and want to bind a function to it you have to mark it as UFUNCTION.

You will notice that it even compiles without the macro but if you test it your bound function wont get called.

ye ! thats a good one , I ran into a problem earlier due to that when my timer was not calling the function and I was wondering why

I highly doubt that but if anyone could prove me wrong I’d love to know.

Main purpose is to expose elements to code reflection.

For UObjects this is true, UObjects are memory managed by UE4 by reference counting. If you have a UObject* variable in your class and it isn’t declared a UPROPERTY, your UObject can be falsely garbage collected!