Howto fix: circular references
If I have an inventory variable in Mycharacter, and a HUD widget. Then the HUD needs to know about the players inventory and the player needs to know about the HUD in order to create it (among others). So they will both reference each other, or at least cast something to another like "CastToMyCharacter". This however creates a circular reference. In C++ that's fine (in this case) but for blueprints it seems to bug the engine pretty badly causing weird side-effects/bugs/crashes.
I tried event-dispatchers, interfaces, not using variables but only CastTo-nodes. But nothing helped. As soon as I either use a variable of the type MyCharacter in the HUD-widget (even if it's not set nor used) or if I use the node CastToMyCharacter, it will immediately count as a circular reference.
I could create a 3rd blueprint and put every single public variable in the game in here. That will solve it. But as you might imagine, that would be extremely and extremely hard to maintain and messy as well.
I also tried an event dispatcher in MyCharacter and only have it input a simple float-variable. No player reference. But sadly that won't work either because the HUD requires a reference back to player for the event to work... sigh... And the engine won't let me bind the HUD to the player, from within the player-blueprint (where I have a self-reference) either :/
What do I do?
Video of the compile loop: https://www.youtube.com/watch?v=fs6GQ3BZlGs&feature=youtu.be
Update: Also applies to non-UMG classes. It's not limited to widgets only.
I ask this question because of the response in this topic: https://answers.unrealengine.com/questions/185609/lots-of-bugs-need-help-with-short-video.html
The only variable that you need to create for this is a variable that will reference the HUD Blueprint inside MyCharacter Blueprint. After creating your HUD, create a new variable inside your MyCharacter. Select the variable's pin type under Variable Type and search for your HUD. In my case, my HUD was called First Person HUD so I chose that. At this point, you still need to fill this variable. To do this; Firstly, create a custom event in your MyCharacter, and add a new input to this event. This input's variable type will be your HUD again. From this custom event, Set the variable that you created earlier with the input value of your custom event. Then, inside of your HUD blueprint, cast to your MyCharacter (mine was called FirstPersonCharacter) using the Get Player Character as the the object. From the As MyCharacter return value, pull the custom event that you created earlier in your MyCharacter Blueprint. Now plug a reference to self in the in value. the result; your MyCharacter Blueprint has a reference to your HUD. And you can reference your MyCharacter from the HUD the same way we just did over and over again using the Get Player Character and Casting to your MyCharacter.
The images below will probably be easier to understand then all of this text. Take care!
The image below is from my HUD Blueprint called First Person HUD. The Image below is from MyCharacter Blueprint called FirstPersonCharacter.
Confirmed as bug by Epic staff member in this post: https://answers.unrealengine.com/questions/185609/lots-of-bugs-need-help-with-short-video.html
So almost every blueprint project now is possibly 'unstable' then. I hope they fix it fast.
Follow this question
Once you sign in you will be able to subscribe for any updates here