Can I run BuildPipeline.BuildAssetBundles in playmode? - c#

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.

Related

c# Application to create Unity Package

I want to make a Windows Desktop App in c#, that a user can drag and drop files (models, textures, materials) onto, which then bundles these assets into a Unity Package.
Can this be done from outside Unity using .Net, or can it only be done with Unity's own editor? If so, what NuGet package would be used as there are many Unity packages?
Many thanks.
If I understand your question correctly you wouldn't need an app for this.
Unitpackages can afaik only be created using Unity.
Unity has Command Line Arguments which allow you to export packages via a cmd call afaik like e.g.
C:Path\To\Unity.exe" -quit -batchmode -nographics -projectPath "C:Path\To\A\Unity\Project" -exportPackage "Assets" "C:Path\To\Export\File.unitypackage"
I don't know why you want that, but you can simply put the files you want into a folder as you wish and then convert to a zip file for easy transport internet if that is what you wish. I dont see the point in making a Unity Package for that.

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

C# - (Unity .NET project) How to include a reference script but should not be compiled

I am newbie and I apologize in advance.
I have a Visual Basic solution with two projects inside
I would like to build a dll that excludes the script called "Group" in order to be able it to enter separately as source code (free to be modified ).
The problem is that if I exclude this file, the build does not run for missing references.
I tried another way by separating this script into another project and inserting it as a reference.
After build, I thought to delete this dll and replace it with the source code. Error!!!(Unity Crash) Obviously the two dll did not reference a Group.cs file, but they refer to the DLL that contains the script called "Group."
I also tried to add this file as a link ... nothing
I am sure that my approach is wrong, but I'm no expert to understand the right way to go...Can someone help me?
Thanks so much!!!
Maurizio
Put your file in a folder that begin with a dot "."
Unity will ignore this folder during the compilation

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.

Unity3D removing project references in MonoDevelop

I am trying to use Mono.Data.Sqlite in my Assembly-CSharp-firstpass project. In MonoDevellop, I right click on the project, edit references, and add Mono.Data.Sqlite to the references. If I build from Mono, everything goes smoothly and and no errors are produced.
When I move back to Unity3D, I always get the error saying that Mono.Data.Sqlite cannot be found. If I then close Unity + Mono and reopen both, the reference to Mono.Data.Sqlite is gone!
Anyone know what is going on?
So after further Googling and Doc reading:
Unity3D rebuilds the project files every time something changes in the Scene/Assets. This means that the added references were being reset and they couldn't be found by Unity.
The solution is to find the needed DLLs (Mono.Data.Sqlite in my case) and copy them to the Asset folder of the project.
If you want access to the DLLs you'll want to put them into a folder called "Plugins" in your Assets folder - Plugins are loaded first, so dotnet assemblies in plugins will be avaiable to you when you want to write code against them.

Categories

Resources