CreateWidget cannot be used on Player Controller with no attached player. Error

Hello,

I’m following a single player tutorial video, when I try to add a widget to the viewport using BeginPlay in my player controller I get “CreateWidget cannot be used on Player Controller with no attached player.” Error.

This is a brand new project in 4.25, this is all that’s created. I’ve tried adding references to self based on what I found online, but I’m not seeing anyone with similar issues in blueprint. I did confirm that this class is inheriting from PlayerController in class settings. What am I doing wrong here?

Hey,

Thank you for your reply!

A. I can’t find anywhere how you would link a player controller to a pawn via settings, I have a custom gamemode with everything including the pawn defined in there.

B. I think you may be right, construction script is probably better for getting values like screen resolution before creating UI,

C. Based on what I found searching, I do think your right about this. The tutorial I was watching uses an older version of the UE, there may have been framework changes to the order of things.

D. Thank you for this point, this is a great tip and I’ve taken this down in my notes.

Your right about delay, main graph only, no construct script or functions.

BTW1: Thank you again, a great tip, I think I had a little different of an idea of the construct script’s use, I understand now.

You can breakpoint the construct script, and it looks the error happens right as Create Main Menu Widget fires, this is probably because, the startup order, like you said.

Moving everything to BeginPlay fixes it immediately, even without a delay. Although this really was bugging me as to why this wan’t working, I really wanted to understand why, but honestly your BTW2 is great advice that I should have known to follow in the first place. It was late at night and I wanted to understand the framework better, but again, you are right about tutorials, I wanted to know how you would do procedural logic, from a rougelike dungeon to, something like a SpyHunter road system. Your right, I should learn to take existing projects apart, and experimenting on my own instead of blindly following tutorials, it’s definitely hard to get started with learning to program from a concept.

Thank you for your reply and advice, Cheers!

1 Like