I have gameObjects (the enemies) spawned one by one by a spawner script.
The spawner script have an arrey of Serialized scriptableObjects (waveConfig), each containing different variables regarding the gameObjects.
When I run on both a local build and the editor,
with the build as server,
the build runs just fine, and on the editor I can see the gameObjects spawned in the same location (but not the editors’ player) and the screen is stuck with this error:
NullReferenceException: Object reference not set to an instance of an object
EnemyPathing.Start () (at Assets/Scripts/EnemyPathing.cs:14)
If the build as the client and the editor the server, it seems to run OK, but the bulid is giving the error.
public class EnemyPathing : MonoBehaviour
{
WaveConfig waveconfig;
float moveSpeed;
List<Transform> waypoints;
int waypointIndex = 0;
// Start is called before the first frame update
void Start()
{
moveSpeed = waveconfig.GetMoveSpeed(); [I]<== line14[/I]
waypoints = waveconfig.GetWayPoints();
transform.position = waypoints[waypointIndex].transform.position;
}
Thank you for engaging !
I have found a solution, but still have a question…
The thing was that EnemyPathing script (which is part of every enemy spawned),
has a Start and Update methods that access the varuable (waveconfig).
I have added:
if (hasAuthority == false)
{
return;
}
Now, from what I understand, this would only let the server access to this script, right ?
Is there another way to do so without having to chack for hasAuthority for every gameObject every frame ?
If the server has authority over the networked gameobject then yes hasAuthority would only be true on the server. It is possible to assign authority to one of the clients though, and in that case hasAuthority would be true on that client. You can also try checking isServer.