CreateWidget cannot be used on Player Controller with no attached player.
And I cannot figure out how to attach a player to a Player Controller. The issue is that I need to use “Spawn Actor From Class” to get the player controller, since at the beginning of the game the server and the client are completely different.
I made the player controller class, made a blueprint of it, and now I cannot add widgets to it. It all seemed straightforward but I don’t really understand why it doesn’t let me add widgets.
I use [WIDGET]->AddToViewport(); to add the widget, and it worked before, but I had to change it because it would show on both the server and the client.
Edit: What worked in the end was adding a player manually in the scene and spawning the second player with the second controller set in the gamemode.
You should not spawn them yourself, PlayerController is created automatically for each player and you can use simple ”Get Player Controller" or to make things a lot easier and cleaner place HUD initiation code in to PlayerController it self, then you don’t need to get controller at all and leave pin as it is (or use “Self” node). There other ways to get PlayerController, some classes holds reference to related controller, for example Pawn will have controller that possess it and you can get it via “Get Controller” (it a function of Pawn class).
If you do it in PlayerController this should work in multiplayer too as local PlayerController stays in local computer memoery.
That’s interesting, but I’m not sure what happens when I try it. The error persists but there are some changes in the viewport, and only in the viewport of the client, which is a good thing. However, I don’t understand the changes.
Create Player spawns the player controller defined in your gamemode. As long as you go to your gamemode and choose BP_MagicPlayerController as your player controller, just do “Create Player” and then use the “Get Player Controller” node to get the player controller that was created. If you use Controlled ID -1, then the first player controller will be numbered 0, the second will be 1, and so forth.
I suggest putting your player-specific logic into the pawns instead. It’s simple to switch which pawn your controller controls (and each different pawn can have very different behavior). Your controller should just pass input from keyboard/mouse/gamepad down into your pawns.
[quote=“anonymous_user_5097d118, post:4, topic:368118, username:anonymous_user_5097d118”]
That’s interesting, but I’m not sure what happens when I try it. The error persists but there are some changes in the viewport, and only in the viewport of the client, which is a good thing. However, I don’t understand the changes.
In that pic, IF you don’t click “spawn player controller”, and you run the obj out to the spawn actor owner input, does that put the player controller in that actor?