How to run a function inside Vuforia's DefaultTrackableEventHandler.cs - c#

I'm trying to run a function inside DefaultTrackableEventHandler.cs after Vuforia detects the target by using the protected virtual void OnTrackingFound() but Vuforia can't detect the namespace that I'm using which is saved inside the Assets folder plus whenever I restart Visual Studio, every code that I've added to the DefaultTrackableEventHandler is deleted and the file is reset back to its original state. I think the problem might lie in the fact that DefaultTrackableEventHandler.cs is located inside the Packages folder while the script that I'm using for the namespace is inside the Assets folder.
How do I resolve this issue?

Related

Unity3d 2019.3.10 UnityEngine.UI; not found

I want to display the number of coins on the screen, but I have error into my VScode:
The type or namespace name "UI" does not exist in the namespace
"UnityEngine"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Main : MonoBehaviour {
public Player player;
public Text coinText;
public Image[] hearts;
public Sprite isLife, noneLife;
void Start() {
}
void Update() {
coinText.text = player.getCoins().ToString();
Lose();
}
}
For Visual Studio Code (VSCode) not detecting UnityEngine.UI, you can follow these steps to solve possible issues.
In Unity, go to Window/Package Manager
Search for "Visual Studio Code Editor"
Downgrade to version 1.2.3 (or upgrade to 1.2.5, seems like 1.2.4 is the problem)
In Window/Package Manager, Search for "Unity UI"
Re-install the package
In Edit/Preferences/External Tools, check the "Registry packages" option
In Edit/Preferences/External Tools, click the "Regenerate project files" button"
If that didn't fix the problem, downgrade "Visual Studio Code Editor" to 1.1.3 instead.
Then you have to manually delete .csproj and .sln files at the root of your project and restart Unity.
From this unity thread:
1) Close Unity and any code editors you have open
2) Make a backup of the Library folder from your project folder to your desktop
3) Delete the Library folder from your project folder
4) Open your project (Unity will rebuild the Library folder)
5) Close Unity
6) Delete the newly generated Library folder
7) Move the Library folder (you backed up earlier) from your desktop back into your project folder
8) Open your project
9) Open one of your scripts
UnityEngine.UI should be fine now
I had a same issue. I changed visual studio code editor version to 1.2.1 in Windows > Package Manager > Visual Studio Code Editor section; I hope it helps
Switch to VS Community under External Script Editor.
Regenerate project files
Switch back to VS Code.
DON'T regenerate project files.
Restart everything.
Hi Bro Solved the problem, very simple. Delete Unity Hub.If not solved, download a new version of unity, don't run it with the hub. Then run it with the hub.

Multiple script and namespace errors on a previously working Unity project . Type or namespace name 'GUIColorOverride' could not be found

I had some unusual errors on a relatively small Unity project with six c# scripts written in Visual Studio. It was all working fine, and I came back to it after the weekend. Upon opening, there were 18 new errors which were preventing the code from compiling and I spent several hours trying to figure out what was going on.
The main errors were saying things like Type or namespace name 'GUIColorOverride' could not be found and associated script cannot be loaded, assign a valid script, even though they were linked and I could see the scripts had no errors in Visual Studio. I even did a full Unity uninstall and rebooted, then a clean install. This didn't fix it.
I tried a number of other things such as backing up the scripts from the assets folder and then deleting them. Opening the project and pasting them back in as 'clean' new scripts. This didn't work. I am using Unity's Cloud Collab so was even able to use this to go back to earlier pushes of the project (which had all worked). Nope.
Solved it! The issue was that the local Projects folder I had been using was connected to Google Backup and Sync. This messed with some of the files in some of the folders in PackageCache in Particular in the MyProject > Library > PackageCache > com.unity.timeline#1.2.13 > Editor > directory.
[FIX] To fix and prevent this from happening in future, I turned off Google Backup and Sync for my Unity Project(s), and am now exclusively using Unity Collab and Git. Using the specific errors that were showing in the Unity console, I located the exact path of the Unity-created files that were causing these errors in my broken project, and replaced them with the same files from a working project. This fixed all of the errors. There must have been some corrupted or partially synced files in these folders which caused Unity to have a tantrum. Hope that helps someone!
You should exclude these from the Backup!
Basically you can exclude anything that would also be excluded from git via e.g. this "official" .gitignore file for Unity projects.
Any file and folder listed here will be regenerated by Unity automatically and should not appear in any version control / Backup.
The entire Library folder in particular is part of it since its content changes quite rapidly and is recompiled every time you change a script, install/remove a package etc.
Checkout Unity Manual - Behind the Scenes for more information in detail
When backing up a project, or adding a project to a Version Control Repository, you should include the main Unity project folder, containing both the Assets
and ProjectSettings folders. All the information in these folders is crucial to the way Unity works. You should omit the Library and Temp folders for backup purposes.
To solve an already present issue with the Library folder you can most of the times fix it by simply closing Unity, deleting the entire Library folder via your file browser and opnening Unity again → Unity will rebuild the Library

Can I run BuildPipeline.BuildAssetBundles in playmode?

Hi everyone I need a help with Unity. I need to run the method 'BuildPipeline.BuildAssetBundles' after I click a button while i'm using the built software, is it possible to do? I know that this is an editor script, but is there a way to call it in a 'non-editor script?
Thanks at all
No classes that are part of the UnityEditor namespace will work in a build. Unity will simply refuse to try to do it. You can use things from AssetBundle because it's a part of UnityEngine, but you can't use BuildPipeline in a build. Unity allows the UnityEditor namespace to be include only in files that are marked as being editor files, usually by being placed in folders called "Editor" and those files are excluded from the build.
You can use BuildPipeline in playmode inside of Unity Editor's player though, but that's about it.

Load serverside c# scripts and then attach a scripts to game object

I have Two question.
1. How can I load existing c# scripts from external path to my apk file.
2. How can I attach scripts in a game object.
Assuming that I create a sphere and then build an apk file. when i run my unity app, you can see the sphere,which is not moving. After building apk file, i'd like to move the sphere .
Scripts are compiled objects, so I believe you can't load them in dynamically. In addition, I believe Android wouldn't allow it anyway, as loading scripts in dynamically is considered a security risk. You could download an app, which downloads new virus-type scripts that weren't in the original code...
you can attach C# script to game object and disable it(unchecked), and after build apk file you can enable it by a button in run time,

access another script from FirstPersonController

sorry for my English!
I have scripts called "MYJoystick.cs":
public class MYJoystick : MonoBehaviour
{
public static string myX;
}
and I want to access "myX", from "FirstPersonController.cs" in unity 5. I want to write this in the Update in the FirstPersonController Like this:
private void Update()
{
MYJoystick.myX += 1;
}
but it says "The name `MYJoystick' does not exist in the current context".
How can I fix this? should i add Using In FirstPersonController? using what? what is the default namespace in unity? I also tried to add Namespace for my script, but it didn't work too!
I just had this problem.
http://docs.unity3d.com/Manual/ScriptCompileOrderFolders.html
The basic rule is that anything that will be compiled in a phase after the current one cannot be referenced.
The phases of compilation are as follows:
Phase 1: Runtime scripts in folders called Standard Assets, Pro Standard Assets and Plugins.
Phase 2: Editor scripts in folders called Editor that are anywhere inside top-level folders called Standard Assets, Pro Standard Assets and Plugins.
Phase 3: All other scripts that are not inside a folder called Editor.
Phase 4: All remaining scripts (ie, the ones that are inside a folder called Editor).
Your FPSController c# script is in the standard assets folder, this is compiled before your other custom c# scripts that are in another folder.
To fix this you could rename the 'Standard Assets' to another name, or put this folder into another folder or take the FPSController script and put this with your other scripts.
A better solution would be to copy the FPSController standard assets script and put this into your custom folder and then modify this script instead.
I tried to change the compilation order of the scripts as a better solution, but it didn't seem to work. That's only for run time with Start() and Awake() I think between scripts.

Categories

Resources