Hello
I need a simple way of spawning red players on a red spawn point and blue players on the blue spawn point. I have no clue how to go about it. Is there anyway i can assign which NetworkStartPosition each player starts on using code by passing in the one I want it to spawn on from my own array. Any help would be very appreciated.
Ben
Hi Ben,
I’d suggest taking a look at custom spawning: https://docs.unity3d.com/Manual/UNetCustomSpawning.html
Are you using the High-Level API or Low Level?
I’m not entirely sure what the difference between HLAPI is and Low level. If you could explain that would be brilliant and thank you very much. I’ve tried searching for custom spawning but nothing really came up. I’ll have a look and get back to you on what level API I’m working with
Hello again. From what I’ve looked at I believe I’m using the HLAPI but I’m not too sure. I didn’t know that LLAPI was a thing until you said it. Will it be a problem that I’m using HLAPI or is this ok.
Thank you and sorry for the unclarity
Ben
The (High Level API) HLAPI provides you with an easy-to-use system for managing players, networked objects and general aspects of your multiplayer game. The HLAPI includes the Network components that can be added via the inspector.
The Low Level API (LLAPI) also known as the Transport layer allows you to code your own networking systems. It can be harder to work with if you are new to multiplayer game development but for its complexity, it gives you more freedom.
It will not be a problem if you are using the HLAPI, you will be able to follow the manual to create your own custom spawners. It is also possible to create your own Network Manager, this will allow more customisation for your game project.
Hope this helps.
@Benvictus yes thank you. That really helps. I’m using the HLAPI. I’ve got the player to spawn now using ClientServer.AddPlayer() then called a method on the player start to move it where I want. The problem is that it doesn’t apply it to the correct team. How would I get the player game object in the same function as where I spawn the player so I can assign a few variables? Can you please help with this. It would be much appreciated. Thanks
Ben
Hi @BenHowick
I’ve not created my own custom team based spawner myself so I can only suggest a theory on how you can go about it.
I will set up a team based spawner in a personal project to see what can be done. Are you able to provide me with the script you are using to spawn your players? Also, are you using a Custom made network manager script?
Kind regards.
I’ll go on my computer and see if I can send the code across if I remember to. I’ve got it so that I can set the team to the player as when the player spawns I’ve got it so that it picks up the variable then it should pass it to the server to set server wide but the [Command] I’ve got set up doesn’t seem to want to call.
I’m using the network manager made by unity but spawning the player when the user selects which team they are in. Which then saves the team locally then the player calls a function that passes it over on start then tries to call the command.
Also a quick question. Does the [Command] function need any specific requirements to be called?
Thanks
Ben
I was able to create a basic team spawner that assigns the client a team when they connect and spawns their playerPrefab at the team’s spawn point.
I’ve attached it to this post. (used Unity version 2017.3.0f3)
- Import the package into an empty project.
- Add scenes to the Build Settings and network manager.
- Build and Test with multiple clients.
I basically override the OnServerAddPlayer() function in a custom NetworkManager and change where the player spawns.
Hope this helps!
3362553–263457–TeamSpawning.unitypackage (50.5 KB)
What is it you are trying to do and do you have some code?
The only requirement should be that it is in a class that derives from NetworkBehaviour and is invoked on the player GameObject.
Right thank you very much @Benvictus ill have a look at it tomorrow. I’ve sorted out the command as I hadn’t called it from the player object. Thank you and I’ll get back to you tomorrow if I need more help. Thanks.
Ben
Just checking to see if that package was helpful.
Hi @Benvictus sorry. I haven’t really had chance to have a look at it yet. Now that it is the weekend I should have some more time on my hands so I should get a chance to have a look.
One question though. Is there anywhere I can find the code for all the functions like AddPlayer() etc. This would be helpful so that I know what is being overwritten.
Thanks
Ben
@Benvictus it is working for player one but not for the client connected to the server. none of the players show up. Thank you very much for your help but I’ve just managed to find a way to do it by passing a load of variables around.
I’m now trying to add a respawning method which is proving harder than expected.
Thanks again for the help.
Ben.
You are not overwriting any code that you need, it just means that we are extending/modifying the function. I’ll get back to you after I search to see if the code for the functions is available.
Is this in my unity package? Ensure that Auto Create Player is enabled on the Network Manager.
@Benvictus right ok. That’s alright then. Override sounds like it isn’t running the other code. That’s all.
Yeah it’s your package that isn’t working. I’m pretty sure that the auto create player is enabled as it works on the server player person
Thanks
Ben
Hi @Benvictus this was a good example but how would you do this with respawn
I have tried to implement this to player health script but without success.
Grateful for help.