I am following the official Unreal tutorial on YouTube:
Battery Collector
And I get the “BlueprintReadOnly should not be used on private members” error. My code looks the same like in the tutorial:
private:
/** Static mesh to represent the pickup on the level */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pickup", meta = (AllowPrivateAcces = "true"))
class UStaticMeshComponent* PickupMesh;
and
private:
/** Box Component to spawn pickups */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Spawning", meta = (AllowPrivateAccess = "true"))
class UBoxComponent* WhereToSpawn;
My second question is how to write the value of Category:
Category = “Pickup”
Category = “Spawning”
or
Category = Pickup
Category = Spawning
EDIT:
protected:
/** Static mesh to represent the pickup on the level */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Pickup", meta = (AllowPrivateAcces = "true"))
class UStaticMeshComponent* PickupMesh;
and
private:
/** Box Component to spawn pickups */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Spawning", meta = (AllowPrivateAccess = "true"))
class UBoxComponent* WhereToSpawn;
I have just changed private to protected in one place in my code (without changing the other private) and … it works! It’s really crazy!
its not crazy that it works when you make your blueprint properties protected:
Consider that each blueprint you make out of some c++ class is a child of your c++ class. So make a private member a UPROPERY(WithSomeBlueprintParam) makes no sense at all, since your blueprint wont have that attribute. Although you could create a getter function which is at least protected and this could return your private member. Dont forget to make it a UFUNTION so make it working.
For your second question:
it doesnt matter if you write Category = PickUp or Category = “PickUp” it works both ways. But you can do something like this Category = “Some Useful Category” for having Categories longer than just one word.
Anyways, i would stick to one solution of those, since its maybe more readable if you define your categories with the same option.
Maybe someone likes it to name categories always with " " since it will be coloured as a string in your ide.
Glad you’re following along with the battery collector tutorial! You’re just missing an “s” on the end of AllowPrivateAcces on your PickupMesh, which is probably why changing that one to protected allowed you to compile.
i didnt see that specifier earlier. But it seems there is a misunderstanding on my side what blueprints really are.
I always treat them as children of a baseclass and they do behave like one but maybe it is also intended to have a baseclass blueprint which can be treatened as a somewhat baseclass copy?
You are right! Now, all works! I’m starting my adventure with UE4 C++ and just make mistakes, sometimes silly ones.
Thank you, guys, for all the posts.
It’s a very good tutorial to learn the fundamentals of UE4 C++. Many people have been waiting for it for a long time. I wish I saw more in the future. You can even make not full projects like the battery collector, but short tuts (a separate playlist) that showing how to use all these characteristic elements in UE4, for example the C++ code for AI, animations, etc. You can do that in your free time. It’s important not to concentrate on blueprints only.