I’m trying to make a simple LAN multiplayer demo with the FPS Template. I have 2 Blueprint character classes. One is named Hunter, the other Creature. Each have their own UMG (Blueprint Widget).
Eeehm, that might happen because in Multiplayer, you have a version of these Characters on each game.
The Hunter Blueprint has an Actor that the Hunter Player controls in the Hunters Game, but also one that is controlled
over the LAN in the Creatures Game. You are creating the Widget on BeginPlay. BeginPlay will be called on EACH instance.
That means, that not only the Hunter in the HunterGame calls that, but also the duplicated HunterActor in the Creatures game.
Resulting in adding the Interface to him too. Same goes other way round.
You will want to do it like this:
I think this should make sure that only the local controlled Pawn calls it and the LAN Pawn will not.
Reach out to me if this is not working or if you did not understand something of what i’ve written. (:
(Note: I did not use any Widget Class there, nor added it to the viewport. You will want to do this the same way you already did at this part)
Well, I think I’ve understand your explanation, thanks!
But I don’t know how to solve my problem ^^. I tried “is Locally Controlled” node, but it doesn’t work…
Now, only the server has text : Screenshot by Lightshot
But, there is something that I don’t understand. I created a “Print String” node to the result of “is Locally Controlled” on the client, and the result is “false”. Why ?
Weird, this is perfectly working on my end. I will show you how i have done it:
Create 2 different CharacterBPs, Player1 and Player2. Difference is the Material of the Mesh
and the Widget they create:
Player1:
Player2:
Only the Widget Class is different. The Widgets are the same like yours, just “Hunter” and “Creature”
text on the top mid of the screen.
Now, since we have 2 different classes, i set the DefaultPawnClass of the GameMode to NULL and spawn the
Characters myself. This has to be done on the Server only!
The GameMode Class only exists on the Server. It has no Client Version. There is a function called “Event Post Login”, which
gets called once a Player is connected and has a valid PlayerController. I use this to Spawn the Player. This function also
gives me a reference of the Players PlayerController (still Serverside!). With this i can just call possess on the spawned
PlayerCharacter. You don’t need to call anything on the Client and you also shouldn’t!
So this is the function call on my GameMode:
The “Counter” is just for me, because i needed something to get 2 different Players. The variable is 0 at the beginning, modulo 2 is still 0.
Then, after the first Player joined, i add 1 to it, which makes it modulo 2 equal 1. So i get to different “Branch” results. Nothing really
relevant for your setup. You can decide who is Hunter and who is Creature in your own way.
But as you can see, i spawn the 2 different Players and possess them with the parameter Controller.
And that’s all (:
If you spawn you Pawns by hand, you will want to leave the DefaultPawnClass at NONE, because otherwise the Engine will spawn
it by default. Maybe your error comes from here.
The PostLogin event in your picture, is that handmade? Because PostLogin is a function that already exists. You only need to search it
when rightclicking.