Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Attaching a player to a Player Controller (solved)

I get this error

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.

Product Version: UE 4.12
more ▼

asked Aug 24 '16 at 03:00 PM in Blueprint Scripting

avatar image

19 10 14 18

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

You can use the Create Player node in blueprints to create a new player along with its controller.

more ▼

answered Aug 24 '16 at 08:25 PM

avatar image

2.1k 67 84 77

avatar image octafbr Aug 25 '16 at 07:51 AM

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.

How I had it before What the client looks like Added Create Player (still not sure if used correctly) What the client looks like after. The black bottom half persists with movement

knipsel.png (47.5 kB)
knipsel2.png (841.7 kB)
knipsel3.png (62.8 kB)
knipsel4.png (400.6 kB)
avatar image CleanCut Aug 25 '16 at 03:41 PM

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.

avatar image octafbr Aug 26 '16 at 07:35 AM

The problem is that for this multiplayer game I need player 1 and 2 to have different player controllers, and from the gamemode I can only choose one.

avatar image CleanCut Aug 26 '16 at 03:21 PM

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.

avatar image CleanCut Aug 26 '16 at 03:21 PM

Dangit, whenever I comment it clears the answer acceptance. You'll have to accept the answer again.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Aug 24 '16 at 03:30 PM

avatar image

37.8k 937 172 1123

avatar image octafbr Aug 25 '16 at 08:22 AM

How do I tell the player which player controller to use?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question