#Camera.main.ScreenToWorldPoint() returns camera position in online scene

1 messages · Page 1 of 1 (latest)

weak edge
#

When I do

Camera.main.ScreenToWorldPoint(
    new Vector3(Mouse.current.position.x.ReadValue(),
    Mouse.current.position.y.ReadValue(), 0));```
it returns the `Camera.main`'s position but only in a scene with a NetworkManager. If I move the whole script to a scene with no NetworkManager it returns the expected value. Why doesn't it work in the networked scene?
#

The way I use it it just runs in Update. After checking IsOwner (disabled the check for testing). So not in an RPC or anything. Just locally.

rigid marsh
#

try specifying the camera instead of using camera.main

#

maybe other cameras exist in the scene

#

messing with it or something

#
public Camera cam;
Vector3 mousePos = Mouse.current.position.ReadValue();
Vector3 worldPos = cam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, cam.nearClipPlane));```
probably the first thing id try
weak edge
#

No other camera exists

#

And since this runs on a prefab I cant assign a camera before runtime anyways so I would just assign cam = Camera.main as there is no other reference that is accessible at that time

#

Just for gigs and shittles I did this:

public Camera playerCamera;

private void Start()
{
    playerCamera = GameObject.Find("Main Camera").GetComponent<Camera>();
}

void Update()
{
    Vector3 pos = playerCamera.ScreenToWorldPoint(new Vector3(Mouse.current.position.x.ReadValue(), Mouse.current.position.y.ReadValue(), 0));
    print(pos);
}

I am absolutely aware that this is very bad practice but just for testing. However it is the same result