Quantcast
Channel: Questions in topic: "namespace"
Viewing all 398 articles
Browse latest View live

Null reference exception with static method

$
0
0
My static method that i've set within an abstract class using a custom namespace keeps giving me a null reference exception when i try to pass a Vector3 to it. using UnityEngine; namespace DebugUtility { public class DebugUtility { public static void DisplayInfo(Vector3 pos, string info) { Vector3 pointOnScreen = Camera.main.WorldToScreenPoint(pos); //rest of the code } } } I call it with: `DebugUtility.DebugUtility.DisplayInfo(Vector3.zero,text);`

Unity Can't find script class because of namespace

$
0
0
I have a monobehaviour script. I attempt to add it to a gamobject and I get this dialogue
> Can't add script component 'MyScript' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match.
The usual issue is that the filename and classname do not match or there are compiler errors. This is not the case. I've diagnosed the issue as being related to the namespace. For whatever reason if the class is inside a namespace unity will not be able to find it.
I've tried renaming the namespace but that did not work. It seems to be just namespaces in general. This issue seems to be with just this class as well. I just finished a big refactor of my project and other monobehaviours attached to gameobjects are working fine.
Any clue as to why this is happening? How exactly does unity find classes?
Thanks

Asset store's asset namespace not found (different Unity versions issue)

$
0
0
I bought Rewired from the asset store, and it installed without problems. However, when it comes to using it in scripts, "using Rewired;" causes an error ("the type or namespace name Rewired could not be found"). Now I had to switch Unity versions mid-project, which is likely causing the issue. I started using Unity 5.5.0f.3 but a bug in sprites slicing forced me to upgrade to Unity 2018.1.0f2. Ever since that change, in any new script I created, I'd have to click **File -> move xscript.cs into -> projectname** to get my script to be recognized by my project. So I suspect it's kind of the same issue going on here, except in reverse. Good scripts already in my project won't recognize new namespaces. I tried moving the entier Rewired folder into Scripts, or using **Assets -> Import new Asset -> Rewired__Editor.dll** (may not even be the right file) but nothing worked. I'm wary of messing up my project by playing with something I'm not knowledgeable with. I contacted Rewired for help, but they said to contact Unity.

namespace not found

$
0
0
when i am creating new c# script it is showing errors that namespace not found(although these namespace are default namespaces). i have recently install unity 5.3 . restarted monobehaviour many time,change language from default to english. selected monobehaviour in unity editor --> edit>preferences..>external tools. reinstalled unity 5.3......but nothing solved my issue.

UnityEditor.iOS.Xcode does not exist

$
0
0
So I'm trying to use this: https://docs.unity3d.com/ScriptReference/iOS.Xcode.ProjectCapabilityManager.html _ **Step 1, add the using at the top...** _ ![alt text][1] ![alt text][2] _ **I have the iOS component installed (Unity 2018.2.1f1).** _ ![alt text][3] [1]: https://i.imgur.com/wclPLGK.png [2]: https://i.imgur.com/nq8ZcKO.png [3]: https://i.imgur.com/seNChPN.png

Unity-related namespaces not being detected.

$
0
0
Upon opening up a project, I am met with the same Visual Studio error/warning messages 4 times in a row : The project cannot be added to the solution because a project with the same project filename already exists in the solution. While initially working on a project, namespaces like 'using UnityEngine' or 'using UnityEngine.SceneManagement' work just fine, but again, once I save/exit, and then re-open the project I encounter these errors. * While typing this question, MonoDevelop has opened up on its own. (I do not use MonoDevelop and haven't opened it in years.) Would uninstalling/disabling MonoDevelop help this problem? (Even if it does, I am wondering how to solve the underlying issue.) Thank you for any of your time and help.

unity cant find Android SDK namespaces?

$
0
0
When I try to access the android SDK through scripts by directives (using), unity will allows throw the error CS0246: The type or namespace name `Android' could not be found. Are you missing an assembly reference? using android.os; using android.app; anything that is in the Android SDK will error in unity, why? How can i make this work?

the type or namespace name 'Rigibody2D' could not be found

$
0
0
this is my script![alt text][1] [1]: /storage/temp/123094-screenshot-2018-08-21-061309.png

Unable to reference asset store class from one of my own scripts

$
0
0
I recently bought the Highlighter System from the Asset store. I am able to add the scripts that i have imported as components through the editor, but i cannot reference any of the added scripts from my code! So i have Highlighter added as a component, but in my code, doing myObject.GetComponent() will give me an error saying that it cannot find the type or namespace Highlighter. I have using HighlightingSystem; at the top and it cannot find the namespace or assembly. See the images showing my Assets folder structure. Also note that the scenes supplied by the developer work as well and have no problem finding the referenced HighlightingSystem. Why cant my scripts find the namespace?![alt text][1] [1]: /storage/temp/124113-unityissue.png

StartCoroutine namespace or type not found

$
0
0
Hello, everyone. I'm currently having an issue where I'm trying to call a Coroutine, but I get a namespace not found error on the StartCoroutine method. I have been able to call this method elsewhere in the project. My class declaration is as follows: public class ModelTreeBuilder : MonoBehaviour { public static IEnumerator CreateModelTree() { //call to StartCoroutine is made in here } } And my includes are: using System.Collections; using System.Collections.Generic; using UnityEngine; Please let me know what I've missed.

Assets/Scenes/Player_Control.cs(131,23): error CS0246: The type or namespace name `NotImplementedException' could not be found. Are you missing `System' using directive?

Get All Unity Namespaces (string array)

$
0
0
Hi All, I'm making a custom file creator, where you can specify your file name, location, and also the namespaces to include. I've been able to include all generic c# namespaces, as well as any custom ones (GetExecutingAssembly() and GetCallingAssembly(), respectively), but these do not include namespaces such as UnityEngine, UnityEngine.AI, etc. Does anyone know how I can get a list of all of these namespaces?

The Name 'GUID' does not exist in the current context

$
0
0
I am using the Unity tutorials to make a project. When I go to build the game, I get two errors both from the same script telling me "The Name 'GUID' does not exist in the current context", and it is really frustrating. This is not anything that the standard assets were able to fix when I tried, but I just need help. Thank you, everyone! As well as this, the script it was in is really messy and all in one line. I'm not sure how that happened I didn't do that. using System; using UnityEditor; using UnityEngine; using System.Linq; [ExecuteInEditMode] [DisallowMultipleComponent] [AddComponentMenu("")] public class SceneObjectGUIDComponent : MonoBehaviour { [SerializeField] private string m_Id; [NonSerialized] private bool m_Registered; public string id { get { return m_Id; } } public void Awake() { if (!Application.isEditor) Destroy(this); if (string.IsNullOrEmpty(m_Id)) { m_Id = GUID.Generate().ToString(); } else { var components = UnityEngine.Object.FindObjectsOfType(); if (components.Any(c => c.m_Id == m_Id && c != this)) { m_Id = GUID.Generate().ToString(); } } hideFlags |= HideFlags.HideInInspector; Register(); } private void Register() { if (m_Registered || !Application.isEditor) return; SceneObjectGUIDManager.instance.Register(this); m_Registered = true; } void OnValidate() { // Register in OnValidate becuase Awake in not called on domain reload in edit mode Register(); } void OnDestroy() { if (SceneObjectGUIDManager.IsInitiated) SceneObjectGUIDManager.instance.Deregister(this); } }

The type or namespace name `EditorWindow' could not be found.

$
0
0
Hi, I have a problem while building an android apk file. I tried to reinstal android sdk and jdk, but nothing helped. I checked, that if i delete class "public class ContentDownloadWindow : EditorWindow" I can build the game, but i need this to download data from server. Any solution, please? Should i somehow use this script only in editor? Everytime i build the game, i got errors: "The type or namespace name `EditorWindow' could not be found." "UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x0021f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:187 at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:94 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)"

Problem with using IComparer

$
0
0
I'm trying to use a comparer that sorts a List of Vector2 points by their clockwise position from an origin. I got the comparer code from here https://pastebin.com/1RkaP28U#, and its class is called ClockwiseComparer. Due to the Hydra.HydraCommon.Utils.Comparers line, I figured I would have to add using Hydra.HydraCommon.Utils.Comparers; to the script that I use the Comparer in, which is called Player. So, I create the `ClockwiseComparer comparer` object within Player, and set it to `new ClockwiseComparer(origin)` However, when I try to use it at list.Sort(comparer), the compiler gives this complaint. Cannot convert from Hydra.HydraCommon.Utils.Comparers to System.Collections.Generic.IComparer ______________________________________________________ That was the original problem. Afterward I tried to solve it by making the ClockwiseComparer class into something more resembling `System.Collections.Generic.IComparer`. I changed the namespace to `namespace System.Collections.Generic.IComparer`, and likewise added `using System.Collections.Generic.IComparer;` to the Player class. This simply resulted in cannot convert from System.Collections.Generic.IComparer.ClockwiseComparer to System.Collections.Generic.IComparer Here are both the Player and CounterClockwise scripts from the latter case. using System.Collections.Generic.IComparer; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class Player : MonoBehaviour { [SerializeField] float moveSpeed = 10f; [SerializeField] float padding = 1f; [SerializeField] GameObject projectile; [SerializeField] GameObject flag; [SerializeField] float projectileSpeed =10f; ClockwiseComparer comp; Vector2 origin; float xMin; float xMax; float yMin; float yMax; MeshFilter filter; List flags = new List(); // Use this for initialization void Start () { SetUpMoveBoundaries(); StartCoroutine(delayedLog()); InitializeBaseMesh(); } // Update is called once per frame void Update () { FireLaser(); PlaceFlag(); } private void FindFlagOrigin() { float totalX = 0; float totalY = 0; foreach (GameObject flag in flags) { totalX += flag.transform.position.x; totalY += flag.transform.position.y; } float centerX = totalX / flags.Count; float centerY = totalY / flags.Count; origin = new Vector2(centerX, centerY); if (comp == null) comp = new ClockwiseComparer(origin); } private void ReorderFlags() { flags.Sort(comp); /*for (int i=0; i { private Vector2 m_Origin; #region Properties /// /// Gets or sets the origin. /// /// The origin. public Vector2 origin { get { return m_Origin; } set { m_Origin = value; } } #endregion /// /// Initializes a new instance of the ClockwiseComparer class. /// /// Origin. public ClockwiseComparer(Vector2 origin) { m_Origin = origin; } #region IComparer Methods /// /// Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. /// /// First. /// Second. public int Compare(Vector2 first, Vector2 second) { return IsClockwise(first, second, m_Origin); } #endregion /// /// Returns 1 if first comes before second in clockwise order. /// Returns -1 if second comes before first. /// Returns 0 if the points are identical. /// /// First. /// Second. /// Origin. public static int IsClockwise(Vector2 first, Vector2 second, Vector2 origin) { if (first == second) return 0; Vector2 firstOffset = first - origin; Vector2 secondOffset = second - origin; float angle1 = Mathf.Atan2(firstOffset.x, firstOffset.y); float angle2 = Mathf.Atan2(secondOffset.x, secondOffset.y); if (angle1 < angle2) return -1; if (angle1 > angle2) return 1; // Check to see which point is closest return (firstOffset.sqrMagnitude < secondOffset.sqrMagnitude) ? -1 : 1; } } } Thank you for reading.

unity and c# namespace error

$
0
0
Hello all, I have a problem in Unity and C#. Even though i already imported the namespace in my c# script, it still gives the namespace not chosen error. **" The type or namespace name `GLNeuroTech' could not be found. Are you missing an assembly reference?"** Does anyone know anything about it ? Thanks ![alt text][1] [1]: /storage/temp/127036-unity1.png

Namespace not recognized even its added

$
0
0
im making an AR application using unity and vuforia as my graduation project, so im not so experienced in unity and C#. everything is going smooth till i reached DB, now im trying to connect MySql DB to Unity and found this code some where in internet. using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.Windows; using MySql.Data.MySqlClient; public class DBConnect : MonoBehaviour { private MySqlConnection connection; private string server; private string database; private string uid; private string password; //Constructor public DBConnect() { Initialize(); } //Initialize values private void Initialize() { server = "localhost"; database = "3datlas_db"; uid = "root"; password = "root"; string connectionString; connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";"; connection = new MySqlConnection(connectionString); } //open connection to database private bool OpenConnection() { try { connection.Open(); return true; } catch (MySqlException ex) { //When handling errors, you can your application's response based //on the error number. //The two most common error numbers when connecting are as follows: //0: Cannot connect to server. //1045: Invalid user name and/or password. switch (ex.Number) { case 0: // MessageBox.Show("Cannot connect to server. Contact administrator"); break; case 1045: // MessageBox.Show("Invalid username/password, please try again"); break; } return false; } } //Close connection private bool CloseConnection() { try { connection.Close(); return true; } catch (MySqlException ex) { //MessageBox.Show(ex.Message); return false; } } //Insert statement public void Insert() { string query = "INSERT INTO tableinfo (name, age) VALUES('John Smith', '33')"; //open connection if (this.OpenConnection() == true) { //create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(query, connection); //Execute command cmd.ExecuteNonQuery(); //close connection this.CloseConnection(); } } //Update statement public void Update() { string query = "UPDATE tableinfo SET name='Joe', age='22' WHERE name='John Smith'"; //Open connection if (this.OpenConnection() == true) { //create mysql command MySqlCommand cmd = new MySqlCommand(); //Assign the query using CommandText cmd.CommandText = query; //Assign the connection using Connection cmd.Connection = connection; //Execute query cmd.ExecuteNonQuery(); //close connection this.CloseConnection(); } } //Delete statement public void Delete() { string query = "DELETE FROM tableinfo WHERE name='John Smith'"; if (this.OpenConnection() == true) { MySqlCommand cmd = new MySqlCommand(query, connection); cmd.ExecuteNonQuery(); this.CloseConnection(); } } //Select statement public List[] Select() { string query = "SELECT * FROM tableinfo"; //Create a list to store the result List[] list = new List[3]; list[0] = new List(); list[1] = new List(); list[2] = new List(); //Open connection if (this.OpenConnection() == true) { //Create Command MySqlCommand cmd = new MySqlCommand(query, connection); //Create a data reader and Execute the command MySqlDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { list[0].Add(dataReader["id"] + ""); list[1].Add(dataReader["name"] + ""); list[2].Add(dataReader["age"] + ""); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); //return list to be displayed return list; } else { return list; } } } which is working till i found few errors: 1- Assets/DBconnection.cs(6,7): error CS0246: The type or namespace name `MySql' could not be found. Are you missing an assembly reference? 2- Assets/DBconnection.cs(11,13): error CS0246: The type or namespace name `MySqlConnection' could not be found. Are you missing an assembly reference? 3- Assets/DBconnection.cs(5,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference? i have already added the necessary references but the problem is still there. i tried to search the internet but all of them saying to add references or to copy the necessary Dll files to assets folder in unity which i tried but still didn't work. help plz :(

UnityEngine.UI.dll namespace doesn't exist for 2018.3.0b11 managed plugin

$
0
0
I'm using the beta build for Unity 2018.3.0b11, but I had this issue in 2018.3.0b11 and 2018.2.16f1 as well. I'm trying to build a Class Library into a Unity Managed Plugin. I follow the "Step by step guide for Visual Studio" in this guide: https://docs.unity3d.com/Manual/UsingDLL.html I also watched this video: https://unity3d.com/learn/tutorials/topics/scripting/writing-plugins I moved some classes over that I want to share between projects. When I built it, I have been getting errors like this: The type or namespace name 'EventSystems' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) The type or namespace name 'UI' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) The type or namespace name 'UIBehaviour' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) I have seen articles and blog posts and forum threads all around this happening and followed every guide I could. Close both VS and Unity, check versions, run `Assets -> Reimport All`, etc. Nothing works. Finally, I just found where the `UnityEngine.UI.dll` was being referenced from the autogenerated project that Unity creates, copied it's location at `\Editor\Data\UnityExtensions\Unity\GUISystem\UnityEngine.UI.dll`, referenced it within my plugin class library manually from here. Everything builds just fine when I do that. This doesn't seem correct because none of the guides mention this step. Is there any better way to link these references or some way to get this to work normally? I was hoping for a NuGet package or... something. This seems like a really bad way to create a managed plugin.

The namespace already contains a definition for ''

$
0
0
Hy! I am having a problem with definitions. I can rename a 100 times my script, it says that the namespace already contains a definition for 'Player_Standard' (this is my last try with renaming). When I get bored trying to give a name that is not occupied, I created a random namespace for my script, but it does not changed anything. Same problem appeared. ![alt text][1] [1]: /storage/temp/128177-1.png This picture shows the problem visually. Firstly I did a research before posting here, but I have not got a result.

Unity steamVr Controller namespace not found

$
0
0
I am trying to get the unity steam vr controller input to work but i cant seem to get `SteamVR_Controller` or `SteamVR_TrackedController` to work. any help would be appreciated thanks. using UnityEngine; using Valve.VR; public class AttchToHand : MonoBehaviour { private SteamVR_TrackedObject trackedObj; public SteamVR_Controller.Device controller; private void Update() { if (controller.GetPress(EVRButtonId.k_EButton_Grip)) // It is supposed to return a boolean { Debug.Log("Grip buttons are pressed down"); } else { Debug.Log("Grip buttons are in released state"); } } } Here is my error ![alt text][1] [1]: /storage/temp/129226-untitled9.png
Viewing all 398 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>