Improbable Icon

Any chance you (spatial devs) could explain how Hello World works?

v10-1-0

#1

I’ve downloaded the sample projects and have them all working, and I somewhat understand how Spatial is working. But, it would be awesome to have a description of the various entities and components and how they interact in the demos. For example, in Hello World, I am digging through the code to figure out how players are spawned in. Although I’m slowly figuring it out, documentation around how it all works would be very welcome.

The challenge I am having is that Pirates and HelloWorld do things quite differently. I figured Pirates out but am now having to change my thinking around how HelloWorld operates.

Thoughts?

Thanks!


#2

Hey!

Regarding what Hello World is doing with its player life cycle (e.g. player spawning, deletion) – you may find this post useful: Getting started with Improbable for VR


#3

In order to utilize the player functions from Hello World in a new project, can you list what all components need to exist in my scene? For some reason my player object is not spawning even though I connect to the game.


#4

I suspect that you might be missing the spawner entity in your snapshot. You will need to have a Spawner entity in the snapshot that will receive the Command requests and perform the actual entity creation – do you have that ?


#5

I do not have a spawner entity. Is that needed for the HelloWorld design pattern? I had one when following the Pirates design but not with the HelloWorld.

Also, something interesting is happening. The SimulationManagerEntity is spawning as I can see it in the Inspector, but I don’t see it when I launch the Unity Client? I used to and don’t know what I changed to remove it.

I do have the ClientPlayerSpawner.cs in my scripts but do not see any entity for it anywhere in the HelloWorld code?


#6

Ok, figured it out… I needed to add the SplashScreenController for it all to come together. I’m still not sure where the player spawner is created but it works now (sort of.) The splash screen doesn’t disappear upon connection but I can figure that one out. :wink:


#7

@chong-u Question, what calls the AttemptToConnect () function in the SplashScreenController.cs? If I don’t add a call to it in the Awake() function, it never gets called? I searched through the code in the HelloWorld example and can’t find where it is called.

Thanks!


#8

@chong-u Another question too… I get the following errors when I connect. The player appears but I am concerned something is not working as intended?

3:10:01.041 ERROR[EngineLogMessageHandler] [Worker: UnityWorker0] Failed to get component reference on Player(Clone) -[WorkerLogger:Unity] 03:10:01.913 WARN [EngineLogMessageHandler] [Worker: UnityWorker0] Incoming command request with ID 1 to entity ID 8 and component ID 1500 was not handled by the worker within the given timeout. -[WorkerLogger:Unity]

1500 is the Heartbeat.schema ID btw.


#9

Hey @VectorXStudios

The AttemptToConnect() function is called when the ConnectButton child GameObject of the SplashScreen is clicked. If you look at the Unity components on that GameObject, you can see an OnClick() handler which directs to the AttemptToConnect() function.

The SplashScreen is something I’m tidying up currently and will hopefully have some improvements coming up soon. Do let me know any errors! The not disappearing sounds weird, do you actually see all your entities being spawned in scene but the SplashScreen just doesn’t disappear? There should be a clientside script on the Player which disabled in when the Player GameObject is enabled.

Next, the

Failed to get component reference on Player(Clone)

sounds like you’ve copied some components across from HelloWorld but there are some components that are depended on but you haven’t copied those too? If this is within the HelloWorld tutorial I’ll clone the repo and try and recreate the error - let me know?

Incoming command request with ID 1 to entity ID 8 and component ID 1500 was not handled by the worker within the given timeout.

Sounds like a race condition where a heartbeat is sent before the Player is spawned and this is definitely an interesting race condition - do you get it consistently?

Lastly the spawner entity is currently necessary for the HelloWorld design pattern yes. I’m currently tidying up the whole Player connection cycle so that it’s consistent across tutorials and intend to make a longer post detailing how it all works. As a brief overview, everything starts in the Bootstrap script which has a Start() method which runs when you press play in Unity. In the past the SpatialOS.Connect(...) method was run in Start() however now it’s run by the Connect button in the SplashScreen as described above which allows you to retry your connection in the client if you try and connect before SpatialOS is ready. If the SpatialOS.Connect(...) call succeeds, this means the worker has successfully connected to SpatialOS. The SpatialOS.OnConnected += ClientPlayerSpawner.SpawnPlayer callback in the Bootstrap file is then triggered. This calls the static ClientPlayerSpawner class which 1) finds the SimulationManager entity and 2) sends a command to it requesting it to spawn an entity. The SimulationManager entity then runs CreateEntity(...) to spawn the player.

Hope this helps and keep the questions coming! :support:
Ally


#10

Hi @alastair, I had a customer call until the early hours of the day (I’m US time) which allowed me about 8 hours to work on this and actually figured out the flow through a lot of trail and error but thanks for confirming for me how it all works!

The challenge I had with the Splash screen is that the Connect Button was not activated until it tries to connect to the servers, which does not happen until you click it as you mentioned. If I turned it on be default, it works. The screen does go away now as I fixed that issue when cleaning up various elements in the scene. I had some of the components set incorrectly but fixed those as well after a time.

The heartbeat error happens every launch. I’m going to dig into the Player component today and see what I possibly missed there. I’m just happy it actually works now. :slight_smile: