0
\$\begingroup\$

I have a small Unity plugin project set up (working on fixing a broken mod), and the Camera class seems to be missing a method. I've added Unity dll assembly references, and everything is working except this ONE method. (I went by the advice of a tutorial which did this, so maybe there's a more correct way?)

It's about a 600 line file with lots of references to Unity stuff that are working fine, including other Camera references. In fact if I comment this bit out, the plugin builds and works fine.

This is what I'm importing:

using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using UnityEngine;
using UnityEngine.Rendering;

When I inspect the Assembly (decompiled by Rider), this Camera.ScreenToWorldPoint method really is missing (see left view).

pos = mainCamera.ScreenToWorldPoint(new Vector3((float) ((double) mainCamera.pixelWidth * 0.5 - 50.0), (float) mainCamera.pixelHeight * 0.1f, 1f));

ScreenToWorldPoint error

What else can I try or investigate to get to the bottom of this?

(I know this line of code looks like it does nothing, but I believe it actually IS doing something, because this is a Harmony "Prefix". It looks like it's modifying the value of the "pos" parameter passed into the method that Harmony is patching.)

\$\endgroup\$
0

1 Answer 1

0
\$\begingroup\$

My best guess is, that one of the other imports is providing as well a camera and you are using that one instead of the one from UnityEngine. What would support this is that there is no ScreenPointToRay(Vector2 pos, Camera.MonoOrStereoscopicEye eye) or ScreenPointToRay_Injected(ref Vector2 pos, Camera.MonoOrStereoscopicEye eye) in the documentation.

Check the namespace of the decompiled code and if you are using the wrong one, add the correct namespace to the Camera.

\$\endgroup\$
1
  • \$\begingroup\$ When I hover over "Camera", it says the namespace is UnityEngine (which sounds correct). Most confusing is the fact that the other methods that Unity has documented ARE available. This works fine for example: mainCamera.WorldToViewportPoint(new Vector3()); \$\endgroup\$
    – Manius
    Sep 24 at 2:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .