[4.7.6] Blueprints Cast problems multiplayer

Well i got a problem in my project when i play with 2 players in the editor, give me in the log problems about cast to some objects, here is my setup.


Give warnings and then errors about the sun var from PlayerCharacterpawn, and about MyPawn from the UMG after that the editor crash and close.

And when i play solo don’t give problems.

The first problem I see is that on your Player Controller BP class, at begin play you are getting controller 0 and getting its pawn to assing it to the variable. Since you are already in the controller class you should use Get Controlled Pawn directly without asking for the Controller at index 0.

When you play multiplayer it always returns null, because only the server is getting a valid pawn. Remember that controllers only exist on the server and locally on its owner PC.

I would recomend you to always check validity for the references you use in UMG (node is valid); that way you will avoid crashes when accesing null references.

Let me know if this helped you or if you need further help. Cheers.

Well i got the index removed, but the problem isn’t in the controller is in the UMG <-> Pawn, how i get in the UMG the pawn & the controller from the clients, because give me null.

I changed in the UMG from Get Owning Local Player to Get Player Controller Index and works, the index is for local players if your in multiplayer each player is 0 or this is was i think.

Ok, looking closely to the blueprint you’ve shown, when you call the “Get all actors of class” you are then runnin a for each loop and assigning all the values to a single reference, if you have only 1 direction light it wouldnt be rare if it is at index 0 of the returning array; however it would be better for you to check for the first valid object of the array and store only that reference in your variable an then break the loop (use a for each loop with break).

Also, i don’t know how your mechanic works, but with your current setup each client will get its own copy of the directional light instead of the one in the server. that way if you manipulate it with the character only that character will see the changes. Maybe you should check ‘Sun’ as replicated and get its reference from the server with a custom event (Runs on server, reliable).

The other thing that may be causing problems is that you spawn your HUD widget in the same frame your HUD is spawned. Try using a timer to call the function that spawns the HUD widget at least a frame after that. That way you will have all variables set (had a similar problem in the past and that solved it).

As a final piece of advice: always check validity of objects before assigning them to a variable or when you are not sure it will not be NULL, that way you can use 'PrintString’s to track your problems down.

If you keep having problems come back here, ill try my best to help you sort them oout.

Nice! I’m glad you found the solution.

Yes but no, because continue giving problems and no idea why, when i execute multiplayer as individual process give less errors but give errors.
I give you the reply as accept because you help my to solve the other problem :slight_smile: if i got more problems i going to post.