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

How do you use namespace functions?

$
0
0
I have a weird problem that no one seems to be talking about. I'm trying to use namespaces for my script mainly to see how it works but no matter how simple the function is it gives me a nullreferenceexception. heres a example namespace namespaceExample { public class TestClass : MonoBehaviour { public void TestFunction(string message) { print(message); } } } class TestClass2 { public string message = "Hello World!"; namespaceExample.TestClass test; void Test() { test.TestFunction(message); } } can someone explain to my why this happens? I'm using unity 2017.2.0f3

MonoDevelop not recognizing "UnityEngine namespace"

$
0
0
For some odd reason MonoDevelop can't recognize this. I've searched around online and on the forums and nothing seems to work. I've tried uninstalling and re-installing, which at first worked, but the next day I'm back in square one. I've tried setting my .NET framework to the correct version I have installed. I've also tried deleting certain files in the Unity Project Directory as directed by many answers I've found online. Any help would be appreciated! Thanks in advance.

Using variables without overflow

$
0
0
I have a 2 scripts test.cs and test2.cs. I want it test2 to access test, and it works, but i don't want to make a new variable every function. Maybe the code will tell more :D Current Code (works): using MrRockis.Test; namespace MrRockis.Test.Actions { public class test2 : MonoBehaviour { public void Test() { promo = new Test(); Debug.Log (promo.statusText.text); } } } But i don't want to type "promo = new Test(); inside every function! This code gives stack overflow error: using MrRockis.Test; namespace MrRockis.Test.Actions { public class test2 : MonoBehaviour { private Test promo = new Test(); //This row gives me the error public void Test() { Debug.Log (promo.statusText.text); } } } How could i do this without putting "promo = new Test();" inside every function?

Best way to communicate between scripts

$
0
0
Hello everyone. I would like to know what is the best way to communicate between scripts without referencing them through the inspector. I've found some very helpful answers but I'm not sure which is best and why. For example, we have a main script where all our info is saved or loaded and some secondary scripts with info. Most secondary scripts will need to use values from our main script pretty commonly and i know for sure `GetComponent` is not the best way to do it, especially if you are going to reference them a lot . I could also create a variable and then drag the game object that holds the main script to it but then i would need to do that for every single secondary script and some scripts may need to be destroyed in runtime or some game objects may change many times which i think is waste of time, which is why I'm interested in being able to make a whole class static and use it's values or perhaps use namespaces? Any help would be appreciated and sorry for the confusing, I'm really confused as well!

Types and namespace not found...

$
0
0
Ok, so I'm new to Unity and C# but I wrote a tiny script which runs without a problem inside Unity. But when I try to export it (build) I get a bunch of errors all telling me types are not found, and it's pretty much all the types I used... So it doesn't find MonoBehaviour, Vector3 or Transform. The script looks like this : * using System.Collections.Generic; using UnityEngine; public class CameraBehaviour : MonoBehaviour { Vector3 myVectorZ; Vector3 myVectorY; Vector3 myVectorX; Transform myTransform; void Awake () { myTransform = GetComponent (); myVectorZ = new Vector3 (myTransform.position.x, myTransform.position.y, myTransform.position.z+2); myVectorY = new Vector3 (myTransform.position.x, myTransform.position.y+2, myTransform.position.z); myVectorX = new Vector3 (myTransform.position.x+2, myTransform.position.y, myTransform.position.z); } // Use this for initialization void Start () { } // Update is called once per frame void FixedUpdate () { if ( Input.GetKey( "space" ) ) { transform.Translate( myVectorZ , Space.Self); Debug.Log ("Fixed :"); Debug.Log (myTransform.position.z); } } void Update () { if ( Input.GetKey( "space" ) ) { transform.Translate( myVectorZ , Space.Self); Debug.Log ("NotFixed :"); Debug.Log (myTransform.position.z); } } } * I'm guessing I didn't think of a simple thing that ruin everything but I didn't find an answer fitting my problem. Sorry if I'm not clear, not english... Thanks in advance for your answers !

Visual Studio 2017 namespace cannot be found on installed package

$
0
0
I've installed the FileHelpers package http://www.filehelpers.net using the package manager console in Visual Studio 2017 and when I start Unity I get the error message "The type or namespace name `FileHelpers' could not be found. Are you missing an assembly reference?". I am using .NET 4.6. Any help would be appreciated.

AsyncGPUReadbackRequest could not found

$
0
0
I am getting errors like "The type or namespace name 'AsyncGPUReadbackRequest' could not be found (are you missing a using directive or an assembly reference?)" "The name 'AsyncGPUReadback' does not exist in the current context" Although I have included using UnityEngine.Experimental.Rendering. Can you please tell me how to resolve this issue? I am using Unity 5.6.4p4.

Recording video from webCam

$
0
0
Hello, I'm trying to use the script from [VideoCapture](https://docs.unity3d.com/ScriptReference/XR.WSA.WebCam.VideoCapture.html), on editor mode doesn't reflect any issue but when it comes to the deployment on PC standalone, it tells me: The type or namespace name `WebCam' does not exist in the namespace `UnityEngine.XR.WSA'. Are you missing an assembly reference? and I know it changed from VR to XR but I'm not missing any name space. using Unity 2017.3 Here is my code: using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine.XR.WSA.WebCam; using UnityEngine.SceneManagement; public class WebCamera : MonoBehaviour { static readonly float MaxRecordingTime = 15.0f; VideoCapture m_VideoCapture = null; float m_stopRecordingTimer = float.MaxValue; // Use this for initialization void Start() { StartVideoCaptureTest(); } void Update() { if (m_VideoCapture == null || !m_VideoCapture.IsRecording) { return; } if (Time.time > m_stopRecordingTimer) { m_VideoCapture.StopRecordingAsync(OnStoppedRecordingVideo); } } void StartVideoCaptureTest() { Resolution cameraResolution = VideoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First(); Debug.Log(cameraResolution); float cameraFramerate = VideoCapture.GetSupportedFrameRatesForResolution(cameraResolution).OrderByDescending((fps) => fps).First(); Debug.Log(cameraFramerate); VideoCapture.CreateAsync(false, delegate (VideoCapture videoCapture) { if (videoCapture != null) { m_VideoCapture = videoCapture; Debug.Log("Created VideoCapture Instance!"); CameraParameters cameraParameters = new CameraParameters(); cameraParameters.hologramOpacity = 0.0f; cameraParameters.frameRate = cameraFramerate; cameraParameters.cameraResolutionWidth = cameraResolution.width; cameraParameters.cameraResolutionHeight = cameraResolution.height; cameraParameters.pixelFormat = CapturePixelFormat.BGRA32; m_VideoCapture.StartVideoModeAsync(cameraParameters, VideoCapture.AudioState.ApplicationAndMicAudio, OnStartedVideoCaptureMode); } else { Debug.LogError("Failed to create VideoCapture Instance!"); } }); } void OnStartedVideoCaptureMode(VideoCapture.VideoCaptureResult result) { Debug.Log("Started Video Capture Mode!"); string timeStamp = Time.time.ToString().Replace(".", "").Replace(":", ""); string filename = string.Format("TestVideo_{0}.mp4", timeStamp); string filepath = System.IO.Path.Combine(Application.persistentDataPath, filename); filepath = filepath.Replace("/", @"\"); m_VideoCapture.StartRecordingAsync(filepath, OnStartedRecordingVideo); } void OnStoppedVideoCaptureMode(VideoCapture.VideoCaptureResult result) { Debug.Log("Stopped Video Capture Mode!"); } void OnStartedRecordingVideo(VideoCapture.VideoCaptureResult result) { Debug.Log("Started Recording Video!"); m_stopRecordingTimer = Time.time + MaxRecordingTime; } void OnStoppedRecordingVideo(VideoCapture.VideoCaptureResult result) { Debug.Log("Stopped Recording Video!"); m_VideoCapture.StopVideoModeAsync(OnStoppedVideoCaptureMode); } public void TheEnd() { SceneManager.LoadScene("End"); } } I been having this issue for over 3 days and I search for any issue related without any luck. Thanks for the help. Have a good one!!!!

Any reason not to use namespace for scripts for asset store

$
0
0
I noticed that some asset store packages name their assets like this company or project name _ then a class name (like vp_Something). This might be to find the classes from a specific asset faster and to know which classes belong to which asset while typing. But this can be also done with namespaces. Is there any reason to do this instead of CompanyName.ProjectName.ClassName. Also is there any document that defines the default way you should name classes and namespaces for unity asset store?

Custom namespace not found by Assembly-CSharp-firstpass,My custom namespace isn't found in Assembly-CSharp-firstpass using VSCode

$
0
0
I work using two namespaces: one that is game specific, and one that has utitlities that can be re-used by other games. I'm finding that my generic one is not being found by Assembly-CSharp-firstpass in VSCode. So, I lose all my intellisense, and I get lots of red error messages that are annoying. The game compiles fine and runs as expected, but I want my intellisense working. I'm not sure how this firstpass project works. How can I make it so my namespace is found? ,Hi there, I'm using VS Code with Unity 2017.3.0f3, and I'm finding that one of my custom namespaces isn't being found by CSharp. But, other namespaces from say a plugin, are found. When I run my app in the Unity Editor, everything works fine, so my namespace is eventually found when the project is built. But, for some reason, when working in VS Code I'm getting intellisense errors. It's annoying, and it's slowing me down, so I want to solve it.
I'm basically working with two namespaces: one that is game specific, and then I have a general one with utilities that are generic. It's this generic one that isn't found.
Any help is appreciated on how I can solve this.

Unable to resolve System.Data.dll, System.Data.DataSetExtensions.dll error while building Unity HoloLens Application

$
0
0
I'm trying to use Datatables, DataColumns, DataRows in my HoloLens Application. I 'm able to build the solution in Visual studio while I'm getting build erros when trying to build in Unity. Thing I have tried to resolve: Tried to add all the available versions of System.Data.dll in the system but no luck. If anyone faced same issue or able to resolve the issue please help me. @thandusudheer

Getting lots of different namespace errors as whenever i open the same project!

$
0
0
I don't know what to do. Everytime i open the project , i get different namespace errors. each time its different. Sometimes, waterbase error and now UnityEditor.Build error even though the it is present in the namespace. I am sick of this. There just seems to be no way to fix this. :( i have to complete my project. due date is coming up. . using System; #if UNITY_EDITOR using UnityEditor; using UnityEditor.Build; #endif using UnityEngine; namespace UnityStandardAssets.CrossPlatformInput { [ExecuteInEditMode] public class MobileControlRig : MonoBehaviour #if UNITY_EDITOR , UnityEditor.Build.IActiveBuildTargetChanged #endif { // this script enables or disables the child objects of a control rig // depending on whether the USE_MOBILE_INPUT define is declared. // This define is set or unset by a menu item that is included with // the Cross Platform Input package. #if !UNITY_EDITOR void OnEnable() { CheckEnableControlRig(); } #else public int callbackOrder { get { return 1; } } #endif private void Start() { #if UNITY_EDITOR if (Application.isPlaying) //if in the editor, need to check if we are playing, as start is also called just after exiting play #endif { UnityEngine.EventSystems.EventSystem system = GameObject.FindObjectOfType(); if (system == null) {//the scene have no event system, spawn one GameObject o = new GameObject("EventSystem"); o.AddComponent(); o.AddComponent(); } } } #if UNITY_EDITOR private void OnEnable() { EditorApplication.update += Update; } private void OnDisable() { EditorApplication.update -= Update; } private void Update() { CheckEnableControlRig(); } #endif private void CheckEnableControlRig() { #if MOBILE_INPUT EnableControlRig(true); #else EnableControlRig(false); #endif } private void EnableControlRig(bool enabled) { foreach (Transform t in transform) { t.gameObject.SetActive(enabled); } } #if UNITY_EDITOR public void OnActiveBuildTargetChanged(BuildTarget previousTarget, BuildTarget newTarget) { CheckEnableControlRig(); } #endif } }

Facebook Build Errors

$
0
0
I seem to be having hundreds of errors, all of them being 1 of 2 different types of errors. When I try to build for Facebook Gameroom, 806 errors pop up: FormatException: Input string was not in the correct format System.Int64.Parse (System.String s) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Int64.cs:458) System.Convert.ToInt64 (System.String value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Convert.cs:1404) Google.VersionHandler+FileMetadata.CalculateVersion (System.String versionString) Google.VersionHandler+FileMetadata.CalculateVersion () Google.VersionHandler+FileMetadataByVersion.Add (Google.FileMetadata metadata) Google.VersionHandler+FileMetadataSet.Add (Google.FileMetadata metadata) Google.VersionHandler+FileMetadataSet.ParseFromFilenames (System.String[] filenames) Google.VersionHandler.UpdateVersionedAssets (Boolean forceUpdate) Google.VersionHandler..cctor () Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Google.VersionHandler Facebook.Unity.Editor.AndroidSupportLibraryResolver.setupDependencies () Facebook.Unity.Editor.AndroidSupportLibraryResolver..cctor () Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:519) System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:528) System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:77) System.Activator.CreateInstance (System.Type type, Boolean nonPublic) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Activator.cs:372) System.Activator.CreateInstance (System.Type type) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Activator.cs:254) UnityEditor.AssetPostprocessingInternal.GetAudioProcessorVersions () (at C:/buildslave/unity/build/Editor/Mono/AssetPostprocessor.cs:339) UnityEditor.HostView:OnGUI() Following this, nearly every script in the project complain that no single namespace can be found. There are hundreds of these errors: Assets/Plugins/AdColony.cs(45,25): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing an assembly reference? Anyone might know a solution to this? Thank you

Visual Studio doesn't recognise any Unity namespaces

$
0
0
Hi, So I installed Unity 2017 onto my new windows 64 bit system. Now when I open a script I have no access to any of the Unity namespaces. Also, when I click Edit/Preferences/External tool , the external script editor dropdown does not show VS or Monodevelop as before. Any help greatly appreciated.

Missing namespace 'System'

$
0
0
Hello, I get this error "The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)" ![alt text][1] [1]: https://i.imgur.com/8cDwG3b.png I am using unity 2018 and visual studio 2017 all settings are default and this is freshly installed. i already tried reinstalling visual studio but i get the same result.

Blendshape name in Unity importing wrong

$
0
0
I am importing an fbx made in maya with simple blendshape on it but it's got the wrong name when I set it up in unity. In maya, for example, the blendshape node is Blade_Longer, and the target shape is Dagger_Low, now I export the fbx and bring into Unity...but the blendshape in unity is called Blade_Longer.Dagger_Low How do I remove the secondary name of the object and the period? I just want the blendshape to appear as Blade_Longer and that's it

Platform dependent flags required in Using/Namespace definition?

$
0
0
vUnity 2017.3 Developing for both iOS/Android and I am using the following in one of my scripts: using UnityEngine; using UnityEngine.iOS; <---- using Whatever; Does this need to be contained within the platform dependent flags when I build to Android? using UnityEngine; #if UNITY_IOS using UnityEngine.iOS; #endif using Whatever; Thanks in advance!

UnityEngine does not exist in this context

$
0
0
Version: Currently 2017.4.1f.1, repeatable in other versions Exists in both monodevelop and visual studio C# coding for Windows and AndroidSDK Currently affects all scripts using.UnityEngine and children. Currently I'm having an issue with my project where the editor and monodevelop/visual studio both loose access to UnityEngine, despite it being clearing in my Reference library. I've looked through multiple different versions of this question that have appeared for multiple versions and years of unity with no luck. I'm looking for some idea of what could cause this as I've made no changes to any of those libraries before hand, and it seems random when it happens if I revert back to a backup. Attempted Solutions: Delete Library folder Delete all .csproj and cln files to remake them Reinstalled Unity Install a different version of Unity Reinstall Monodev/VS Reimport Assests Reimport All Change .NET framework version Remove GoogleAds plugin(originally thought this was the issue but this happens without the plugin present as well) Tried readding the Reference to the UnityEngine.dll All of these were suggestions I've found in my search, and while they seemed to work for some very sporadically, none of them have fixed my issue. In addition I am unable to post any code for this project for various reasons, though this issue affects all scripts currently.

Unity won't build on Windows after reinstall

$
0
0
I am in need of fixing this problem right away. I am a college student and the game I'm making it's my final career project, deadline in 2 days. ---------- Description: I made my project with Unity 2017.3.0f3. The other day i realized I had only installed the Windows build (As in, no MacOS, no Linux, no anything) and so I uninstalled and installed the exact same version. But now, Unity will not build my game for release on Windows at all. ---------- Errors pop out whenever I try to build the game on its own executable. The error I'm getting is the same type for everything: "The type or namespace 'SOMETHING' does not exist in the namespace 'UnityEngine'. Are you missing an assembly reference?" The game works perfectly fine on the editor and Visual Studio does not seem to detect any error at all. It only happens when I try to build a .exe. ---------- Literally every script, even the ones from the asset store packages I got and the ones I made, have this kind of error and the game will simply fail to build. I've tried the following to no avail: ---------- 1. Reimport all assets 2. Delete the library folder to force Unity rebuild it 3. Delete the .sln files to force Unity rebuild them 4. Uninstalling Unity, turning computer off and on, Installing, turning computer off and on again. ---------- None of the above worked. What are my options? I really need to salvage the project with all of its scenes, scripts and assets and be able to build it. This problem is really getting on my nerves and I have no more ideas.

Can't use namespace 'TMPro' with the TextMeshPro Package (2018.2.0f2)

$
0
0
Hello, I'm having a problem with the Text Mesh Pro package. Whenever I try to use the namespace 'TMPro' in Unity 2018.2.0f2, it says that the namespace doesn't exist. And when I try to open the TextMeshProUGUI.cs in the solution explorer, it says that the file doesn't exist neither. However if it did compile in a previous version (2018.1.0f2) and it works fine, but I can't modify the script in my current version. Could this be a bug? *(Sorry if I have a bad english)*
Viewing all 398 articles
Browse latest View live


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