zaha
(zaha)
March 31, 2015, 7:07am
10
With regards to public vs. private properties, I’m not 100% positive on this as the behaviour was changed in UE4.6 and we’re still on 4.5. 4.5 didn’t care about member visibility, but 4.6 seems to enforce it to an extent. From what I’ve seen discussed on the forums, I think it works like this:
Recommended practice is now to make components private and provide a getter function should they be accessed from outside the class. Like making component properties non-editable, this is to prevent components from being overwritten by “outside code”. This used to be protected through the TSubobjectPtr template, but this has been deprecated.
As mentioned earlier, making the component Visible seems to be all it takes for the component’s properties to be editable. I think this needs to specifically be VisibleAnywhere for the editor to handle the inline component property display.
All of this seems corroborated by the code in 4.6. Take a look at AStaticMeshActor for instance:
private_subobject:
DEPRECATED_FORGAME(4.6, "StaticMeshComponent should not be accessed directly, please use GetStaticMeshComponent() function instead. StaticMeshComponent will soon be private and your code will not compile.")
UPROPERTY(Category = StaticMeshActor, **VisibleAnywhere**, BlueprintReadOnly, meta = (ExposeFunctionCategories = "Mesh,Rendering,Physics,Components|StaticMesh", AllowPrivateAccess = "true"))
class UStaticMeshComponent* StaticMeshComponent;
(...)
public:
/** Returns StaticMeshComponent subobject **/
class UStaticMeshComponent* GetStaticMeshComponent() const;
I’m guessing private_subobject is a macro that currently is public but will change to private once this deprecation is applied.
So, short version, try private and VisibleAnywhere.
Thanks for the info. To supplement your advice, in order for the components to be private members marked as UPROPERTYs, the parameter meta = (AllowPrivateAccess = “true”) is required. Otherwise, a compiler error will be produced:
Is there any documentation on the meta specifiers for UPROPERTY? I searched several times for this, but couldn’t find anything.