Why we need UPROPERTY()

Hi, I wonder why we need UPROPERTY() for components?

	UPROPERTY()
	UPhysicsHandleComponent* PhysicsHandle = nullptr;
	UPROPERTY()
	UInputComponent* InputComponent = nullptr;

It is empty, what does it do?

It’s to be counted for by garbage collection
https://docs.unrealengine.com/en-US/Programming/UnrealArchitecture/Objects/Optimizations/index.html#garbagecollection

Without it the garbage collector could potentially be collected whilst you’re still using it. For components that’s rather unlikely as the actor it’s attached to should hold a reference to it but it’s good to get into the habbit of it.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms