Download

Casting to actor fails from client

Hello!

I am new to the forum and hoping to get a working solution to my networking problem.
Firstly, I have Unity version 4.11.1 and Windows 7.

When I am pressing the key “F”, my “main_character” blueprint checks, whether there is a door or a mystery box in front of me. Opening a door (“Toggle Door” - function) does work. But the function “Open Mystery Box” does not work because it doesnt receive a “signal” from “Cast to MysteryBox”. I did a few screenshots for you, so you will better understand my problem. I’ve found out that if i am unchecking the “Run dedicated server”, my “server player” can open both door and mysterybox. Only the client seem to be not “allowed” to open the mysteryboxes.

I’ve tried at least 4 hours to fix this problem… Can anybody help me?



I had problems uploading the last screenshot. So here is the direct link.
http://www.bilder-upload.eu/upload/71899b-1461279895.png

----- SOLUTION ----

Here in post #10

first thing to do is debug wether you’re line trace is actually hitting the objects you want it to hit by using print string on the hit result. Secondly you need to add print strings to the cast failed and see if the casts are actually failing or not . Finally from the line trace do a sequence and plug it into each cast rather than having the mystery box cast coming from the door cast failing . Post and let me know how you get on

The cast is not failing. My guess is that the server and the client don’t see the same thing. As EniGmaa said - add print strings to the cast failed and see if server and client prints the same thing. If not - then make modifications.

Thank you. I’ve followed your advice and the debugger says object value = none. Also the server is posting the message from print string after the cast failed. What should I do?

adsdsadsasad.png

Yes if the server opens the MysteryBox BOTH do see the MysteryBox!

Is there anybody who can help?

Hello,
here you see my level blueprint. There, a random integer is chosen. I think the random integer is only “known” by the server / player 1. All other players do not know which MysteryBox (here integer) is selected
I’ve tried to edit the “Get Player Character Player Index” to 1, but it didn’t work for server and client.

I had similar problem with my characters aiming.

But first, you have 3 separate kinds of project instance in multiplayer: client, server, and linsten server. You should create macro or function that lets you check what type of code you are running. Has authority will run client code on server if its listen server.
Run game with 2 players, one should be listen server. See how it looks with door and box. If they both in level on server and client, you should check if replication settings are seam on both actors.

Pointers and references are very fishy in multiplayer settings, that box has different pointer on server and different on clients. If that was my code, i would replicate event (RPC to server) for tracing not 2 separate casting ones. So get forward and end point for trace, RPC that and trace on server.

For that get player character by numbers, rabbit hole goes much much deeper. For it to work you need to make proper session joining, selecting leaving etc. There is no tutorial currently about all that, you can get tuts that show beginning (barebones setup) for that.

Do not keep all your code in level blueprint, move everything to GameInstance, everything can cast to it and call its events or functions.

Hello and thanks alot!

Yes, if the listen server is opening a door or a mysterybox,** the client also sees all animations**. Only the client cannot interact with the mysterybox. Though the **client can open the door. **
I am not sure, if I understood the RPC part, I will try and tell you if your tip worked :slight_smile:

I understood that i have to “register” all active players in my game and to move my code to GameInstance. But first (let me take a selife. No Joke :P), I have to watch tutorials about this “GameInstance”.

I am not sure if what i write below is “proper” way of doing unreal multiplayer, but:

I found out that only one blueprint that can multicast to all clients and can replicate event to server is “PlayerState”.
It means that only PlayerState is valid on server and on all clients, every client has its own playerstate, but it alos has replicated player states from server.
PlayerState is lite version of player controller that is replicated.

Recently i created chat system, and only player state allowed me to put all that message logic in single blueprint.

So i suggest you open chest in your local playercontroler, then trigger event in your local playerstate.
It will then do run on server event. Then server opens box, and replicates state.
You can replicate state of box in different ways, but imo having all replicated and multicast events in single blueprint makes it all easier to develop.

Ps.
I am still puzzled why there is no single blueprint that can multicast, run on server survive load level etc. Something like global blueprint that everything and everybody can talk to. Instead we have bunch of small blueprints, that do some of that. This reeks of 1990 fascination for object oriented programming (ie. old ut99 code or habits)

Hm. Sorry I dont know how to do this.

With “PlayerController” do you mean my Main_Character BP? Where do I find my PlayerState Blueprint?

— EDIT —

Ok well. I’ve created my own PlayerController BPClass and assigned it in my project settings. Then, there I call the the function in main_character.
But the result is the same. My client does not know the mysterybox object,

— EDIT 2 —

Hell yeah!

The problem was (of course) replication.
Here is the solution. Thank you all for trying to help me :slight_smile: