Great tutorial! Found only minor issues, really. Good work!
“Take a look at the lines that begin playerEntityTemplate.Add.”
Should be: .AddComponent
CreatePirateEntityTemplate method: This method should be named CreatePirateShipTemplate for consistency. Also name method generating the shops for the snapshot as PopulateSnapshotWithPirateShips and so on for consistency.
No explanation on this commonly used expression: CommonRequirementSets.SpecificClientOnly(clientWorkerId)
In step 3 of writing the CreatePirateEntityTemplate method the order of explanation is confusing: .AddComponent is not available on the object returned by .SetPersistence(true). One must add .SetReadAcl(CommonRequirementSets.PhysicsOrVisual) first. Only then .AddComponent is available. This is because of the interface returned by those methods.
In the Populate* methods of the SnapshotMenu class using ref for the snapshotEntities dictionary is unnecessary.
PlayerInputController is defined under Pirates/Behaviours, which is kind of counter-intuitive. I tried to find it in Player based on the explanation.
Same for ShipMovement.cs. It should be defined at a common place for reuse by both the player and pirate ships.
Brances are not needed due to operator precedence (multiplication is stronger than substraction):
Also, more readable to arrange the code like this:
ShipControlsWriter.Send( new ShipControls.Update() .SetTargetSpeed(Random.value) .SetTargetSteering(Random.value * 30.0f - 15.0f) );
I know, this is not “standard” style, but more readable (at least for me).
“You should use InvokeRepeating in OnEnable(), and cancel it in OnDisable(), in order to prevent unexpected behaviour:”
What unexpected behavior? What happens if we forget to cancel it? A short explanation would help us identifying the issue if it happens due to mistakenly missing those calls out from our code.
2.1: In Unity both the SpatialOS window and its Settings have the same title: SpatialOS. Try to dock them inside a pane next to each other. You get two tabs with the same title, which works, but confusing.
“In the Spatial CLI location field, enter the location of spatial.exe (Windows) / spatial (MacOS) is installed on your machine.”
spatial.exe is on PATH, it says it is “Found” from there. Tutorial does not say that it should be the case (normally).
2.2/2 “Click Add component, and add the new SteerRandomly script to the prefab.” - Now we have this class defined a second time, since it will create a new C# source file. It has already been written in section 1.2. Confused. Should I copy the code here as well?
2.2/3 “Build entity prefabs: In the SpatialOS window (open it using the menu Window > SpatialOS), under Entity prefabs, click Build all.” - It is in the window accessible by clicking on “Settings” in the SpatialOS window. Confused by having the same window title??
Cheat sheet to rebuild this and that: Is it possible (in theory) to automate at least the most common ones of these decisions based on file modification date or diff of some data structures? So they would be built automatically right before starting SpatialOS locally.
2./2: “Look at this file. At the moment, it contains two properties: targetSteering and targetSpeed.”
Naming is not correct. Quoting from the schema file:
// The speed at which the ship wants to move at float target_speed = 1; // The direction the ship wants to be steering in float target_steering = 2;
2./4: “You’ve changed the schema. Whenever you change schema, you need to run spatial worker codegen.”
It would be nice to clarify which button is that on the SpatialOS window in Unity. (Easy to figure, tough.)
4./3: “It’s done when: you see the message printed out in Unity:”
Bad advice. This log message does not appear in Unity, since the collision detection is done only on server side. It shows up on the Console window of the UnityWorker:
WARN [improbable.bridge.logging.EngineLogMessageHandler] [Worker: UnityWorker0] Collision detected with 44 in -[WorkerLogger:Unity] > time=2017-07-27T03:46:44+02:00
I wasted some 5 minutes trying to find it in Unity before I figured where to look…
3/1: InitializeSinkingAnimation method does not exists on the class when the call to it is entered. Adding this function should come first, then its usage in OnEnable.
It would be easier to spot the sinking ships if the cannons would shoot 45 degrees forward.
- There is a console window opened on pressing “Generate from schema” Build button. It is running the “spatial worker codegen” command. This console window should close automatically on successful (all green) build instead of waiting on a keypress.