Improbable Icon

Forums

Player prefab script disabled?

unity-gdk

#1

Iadded a UnityClient script to the player prefab. However it keeps getting disabled by the system.

The function of the script is to send a command to another entity.

Is there a way to debug why it gets disabled?

Thanks,

Robbert


#3

Usually it gets disabled if a Require object is null (Reader/Writer/CommandSender/CommandHandler). You can check if that’s the case, just run your game and activate the script in the inspector. If it throws the null exception, check which variable is null and then check if the worker handling your script has appropriate rights.


#4

Tested the behavior of the script this way before. When enabling the UnityClient script on the prefab throws no exception!?
Stripped it down to the blank-starter-project and added a Player prefab with the (UnityClient) script.
Only have a null exception on another script not related to the Player.


#5

In the blank starter project prefabs are not connected to entities by default. Please check in the Unity Inspector if your prefab has a SpatialOSComponent script on runtime. If it doesn’t, you need to add the lines

GameObjectRepresentationHelper.AddSystems(Worker.World);
GameObjectCreationHelper.EnableStandardGameObjectCreation(Worker.World);

to your WorkerConnectors (I added them to the HandleWorkerConnectionEstablished function). This enables them to associate the entities with the corresponding prefab in Unity.


#6

Yes, got that from the documentation.
When running the game the Player (UnityClient) appears in the hierarchy.

Double checked if I realy got the command sender.
It appears to be null :frowning:
What could be the reason a script can not get a command sender? I thought every script can get a command sender.


#7

Haha alright! :smile:
Glad it works!


#8

Wow, missed the GameObjectRepresentationHelper.AddSystems(Worker.World); in the Client connector!! :roll_eyes:
Missed that one checking the code multiple times.
Sorry!
Thanks for the support!


#9

Haha alright! :smile:
Glad it works!