UPROPERTY() and Pointers

I’m curious if there is a succinct answer to why ATriggerVolume needs to be a pointer for UPROPERTY to work? I tried removing the * and it wouldn’t compile. Then I went into the documentation for UPROPERTY and couldn’t really understand it. Do all “non-primitives” have to pointers when exposing them to the Inspector?

I’m coming from UNITY so I’m a bit shielded from pointers.

1 Like

UPROPERTY has to provide UI and other services to the variables it is used on, so if it were dealing with objects, rather than pointers to objects it would get REALLY complex. Imaging the code knowing that the object Car needed input for make, mode, year and paint color. If its just *Car (the pointer to Car), you basically just show the name of the class and if you need to edit the elements you have to go the the class itself.

It’s a pretty good rule of thumb to use pointers to objects rather than the objects themselves, so that you aren’t moving around big chunks of data every time you process an object.

Privacy & Terms