Hey, I'm wondering what would be more efficient / a better practice.
Should I use Custom Properties for every use of a CoreObject in code, or should I just use FindChildByName if I know the names are not going to change.
This is what I'm currently working on:
I'm putting all of the children of the bet, funds, etc. folders in tables to reference later in code. What I have currently is a custom property on each folder that references each child in the list.
Both methods work, I'm just not sure which one would be better.
I can't speak to performance on this, but it's intended to be very customizable to user preference with organization. A lot of the decision making relates to whether you are going to expose this to others to use, or repurpose it for other uses.
The advantages of a Custom Property:
- Hierarchy independent, so if you reorganize or rename it will keep the reference
- Replacing an object/asset reference is drag-and-drop, and will just work in your script if you don't change the field name on Custom Properties
- Really nice user-facing customization if you're sharing to Community Content. Makes people able to use your script without even reading the code
- And you can add tool tips!
Disadvantages of Custom Properties
- Basically don't work with a variable number of things, so any place you would use
GetChildrend(). You can still make the parent a custom property, but you're going to end up traversing a tree.
- Scripts don't save Custom Properties, so if you use another instance of the script, and it doesn't have the Custom Property references, it will throw an error.
- Gets cluttered when you have a lot of them, and forces you to alternate between scrolling through code and the Properties window.
There's more going on here, and that's just my take, but hopefully it helps !
Thanks. Since what I'm doing is very specific to my object and won't be re-used, I guess it is just a matter of preference. Since I might reorganize later for optimizing networked objects etc., I'd personally go for custom properties.
There is one thing I'd like to note on your second disadvantage point. You can actually set default custom properties on the script assets, the values would just have to be changed for each scenario, but the names would always match what the script is expecting then.
If I recall correctly from @disastronaut's stream with @Tobs , it doesn't really matter? But if you had the script duplicated into many models then you would definitely use the FindChildByName since all your models would be relatively the same whereas custom properties they won't change objects unless you explicitly set them to.