I like the way I can drag and drop UStaticMesh properties. There’s also a way to open asset browser for such fields and start typing the name of the mesh.
What I want is to have the same way of referencing existing components.
For example I have components “first” and “second” both of the custom type inherited from UStaticMeshComponent and want to reference “first” from the second in the special field.
First that comes to my mind is to create a field like that
but in this case I have no way of listing existing items in UI, only typing. It is potentially dangerous because provides no check for the existance of such name.
So is there actually a way to have a property which provides the list of names? Or can you imagine any workaround for such case?
There is FComponentReference, it’s been around forever but is barely known, probably because it’s not very helpful. It’s meant for this purpose, but apparently no-one at Epic thought this was important because it never received any nice customization to help with selecting components.
Essentially it’s the same as using a string property, it just automates the process of getting the specified component’s pointer in code, as well as making your code clearer.
I was lurking in engine source today and found this. There’s no docs and I found only ONE place this thing is used!
Whoever did it forgot the tell everybody else about it:
I’ve tried it with “UseComponentPicket” however I don’t have a list of my components there. My components are all children of the same actor, this might be one of the issues.
As a workaround I made a different solution which cost me a day. I used Details panel customisation to create a combobox which i dynamically fill with strings.
I have
To add on, I was fiddling around with other meta tags and found out there is also “AllowAnyActor”. I tested it out with FComponentReference and it appeared to work well, getting all actors in the scene. Combined with “AllowedClasses”, you may be able to filter only results that you want. I’ve only briefly tested this functionality so I am not sure if there are side effects to using this method.
When you add more settings into UCLASS. Do them one at a time as some do not work and want to error on compile. Same with UPROPERTY had a lot of them that do not seem to want to work and all they do is crash stuff. Not sure if it was the combo of what i was adding.