I’m trying to improve the structure and efficiency of my Blueprints in Unreal Engine 5, and I’m wondering about the best practices for managing references. Specifically, when should I store direct references to other actors (e.g., saving a reference to the Player Character or an enemy manager), and when should I rely on Blueprint Interfaces (BPIs) to communicate between Blueprints?
For example:
If I have a UI panel in a widget, is it better to directly reference it or use an interface to remove the hard dependency?
If an actor (like an enemy) needs to interact with the Player Character, should it store a reference to the player or communicate via a Blueprint Interface?
Are there cases where a direct reference is more efficient than using BPIs, or vice versa?
I want to balance performance, modularity, and maintainability, so I’d love to hear how more experienced developers handle this in their projects.
Thanks in advance!
Here’s an example that I have where I have a Widget that has a hard reference to a blueprint that it is always attached to. If I can get around it, should I try to avoid hard references? I know that the asset will technically be loaded into memory even if it hasn’t been placed in the world, but the panel blueprint here will always be loaded in with the widget, so would it make a difference or would a blueprint interface system be a better workaround.
My rule is: Anything that’s ALWAYS loaded (such as the player) gets a direct reference because it’s easier than an interface and a hard ref doesn’t matter due to it needing to always be loaded anyway. Anything that isn’t ALWAYS loaded gets soft refs or interface calls.
Just as a quick follow-up, are there any drawbacks to each method that would make it better to default to either a direct reference or a Blueprint Interface, and only switch methods under specific conditions?
For example, should I generally default to direct references unless I need modularity, or should I default to BPIs unless I need high-performance frequent access? Are there any rules of thumb that you personally follow when deciding between them in addition to what you have already mentioned?
Well, you want to get a working prototype firstly, even if it’s extremely non-performant then go back and optimize, testing as you go. That being said the best rule of thumb for me is default to BPI’s OR EVENT DISPATCHERS before trying to use hard refs.
You can also just use soft references and load in the object when needed for direct!
Ok, that’s super helpful! I’m actually working on a game I had put out on Steam about a year ago and trying to make some quality-of-life improvements from things I have learned while working on other projects. So, I was just trying to see the best ways to enhance performance and eliminate unnecessary memory usage.
Ok so what I ended up deciding was do use direct references when an actor I know is going to be loaded in no matter when another actor is loaded in. Like if I have a button and a door, it makes sense to just use a hard reference because they’re both gonna be loaded into memory anyway. But if something doesn’t always rely on the other thing being loaded in, I’m gonna try to get away with a blueprint interface.
I’m up for any rebuttals to that idea as that’s just what makes sense to me. Thanks for everybody’s help and clarification up to this point. Very much appreciated!
Right, and when building a level you could even have the button blueprint have a “BP_Door” variable that’s instance editable, then after placing a bunch in the level you can use a drop down in the details panel of each instance of the button to assign it to a specific door hassle-free! Hard references are good when it’s things guaranteed to be within a level together.
You could also build the button inside the BP_Door as a collision component. Drop the door into the map and just move the button component to where ever you need it.