I've recently been given a Unity VR project to tidy up. Very messy, wasn't even on Git. It consists of four Unity scenes, but each one lives in it's own Unity project. I need to have all of them in one project for the build, which is where the current problem lies. The scenes have a lot of scripts in common which were copy pasted between the projects. Some of these are absolutely identical, others have one or two lines difference.
From my research namespaces seemed the best way forward, so that I don't have to go and tweak everything manually. I gave the base scene a unique namespace, worked fine. I imported a second scene as a package and gave it a different namespace.
Now I get a bunch of compile errors to do with the VR scripts from Valve Corporation, e.g.
Partial declarations of 'SteamVR_Behaviour_BooleanEvent' must not specify different base classes
Duplicate 'Serializable' attribute
The namespace 'Valve.VR' already contains a definition for 'SteamVR_Behaviour_BooleanEvent'
I don't understand these scripts and don't want to (and shouldn't need to) mess with them.
An example of what causes the last error is having:
/// <summary>This event fires whenever a change happens in the action</summary>
public SteamVR_Behaviour_BooleanEvent onChange;
/// <summary>This event fires whenever the action is updated</summary>
public SteamVR_Behaviour_BooleanEvent onUpdate;
/// <summary>This event will fire whenever the boolean action is true and gets updated</summary>
public SteamVR_Behaviour_BooleanEvent onPress;
And then this further down in the script (SteamVR_Behaviour_Boolean.cs):
[Serializable]
public class SteamVR_Behaviour_BooleanEvent : UnityEvent<SteamVR_Action_Boolean> { }
Each BooleanEvent gets highlighted.
Am I missing something in my namespace procedure or does anyone know a more efficient way of resolving my issue? I've spent days with this already so any advice would be greatly appreciated.
What I ended up doing was this:
(I cut corners a lot this way and honestly didn't think it would work, but it did somehow.)
-Selected base scene.
-Imported next scene as a package, upon import deselected scripts that showed up with the little gray symbol for being potential duplicates.
-Deleted any duplicate scripts or folders of scripts that were causing errors and didn't automatically get picked up as duplicates when importing.
-Refactored the namespace for the scripts from the imported scene. The Rider IDE has a great way of dealing with this, highly recommend getting the evaluation license just for this feature. This tutorial steps through the namespace refactoring https://www.youtube.com/watch?v=vLrGdx-Ob3g just make sure to switch your IDE inside Unity from Edit > Preferences > External Tools > External Script Editor. Otherwise Rider won't link up to Unity and you won't be able to refactor.
Related
I'm new to Godot coming fresh from unity and I cant figure out how to duplicate an object/node. I've tried the duplicate function to no effect. My most recent attempts try to create child nodes with the same property as the parent. I cant seem to get anywhere, help would be appreciated. Here is my code that tries to create a child node:
Node copynode = new Node();
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
copynode = this;
for (int i = 0; i < 5; i++)
{
AddChild(copynode);
}
}
Also could someone tell me what the object/node/item in the scene is actually called and how to reference it? Is it a Node or a Gamedot.Object or something else? And how do I get and set its properties? I'm just really used to unity and cant figure this stuff out. The only tutorials I find are in the Godot language, and I kind of know c# already so I would prefer to program in that.
Nodes are references
I believe you expected Node to behave as a value type, but actually it is a reference. Let us over what happens:
Here you declare a variable of type Node, and initialize it to a new Node:
Node copynode = new Node();
And then here you overwrite it with the Node on which this script is being executed:
copynode = this;
And then you try to add the Node as child of itself five times:
AddChild(copynode);
Which, of course, does not work. And you do that five times.
Let us be glad this does not work. Because if it did, you have a Node that makes five copies of itself, which each also make five copies of themselves, and you can imagine how that goes. Which is why I will not give you some code to do it.
As you are aware there is a duplicate method. I suspect you expected it to add the duplicate to the scene tree. However it does not do that. Instead it returns the duplicate, and you have to add it (or do something else with it).
Your questions
Also could someone tell me what the object/node/item in the scene is actually called and how to reference it?
I'm not sure what you mean. However, if it helps, this will refer to the object on which the script is executing.
Is it a Node or a Gamedot.Object or something else?
The class Godot.Node inherits from Godot.Object. If you attached a script to a Node the class of your script must inherit form the type of the Node, which could be Godot.Node or a class that inherits from Godot.Node. I hope that helps.
And how do I get and set its properties?
You get and set them like any C# property. Although you should be able to use the Get and Set methods too, but that is intended for dynamic code.
If what you are looking for is how to make the properties available in the inspector panel, you do that by adding the [Export] attribute. For example:
[Export]
public float Speed;
And it should appear in the inspector panel when the object that has the script is selected.
The only tutorials I find are in the Godot language, and I kind of know c# already so I would prefer to program in that.
Most of the tutorials are in GDScript because:
There are two Godot builds. One with C# and one without it. But both can use GDScript. Thus GDScript is useful regardless of which build you are using.
Translating from GDScript to C# is not difficult. It is mostly the naming convention (and some edge cases, which you are probably not encounter when you are beginning). See C# API differences to GDScript.
The way C# is used with Godot follows C# conventions. I'd argue that it follows them closer than Unity. Although there are some rough edges when it comes to signals and async methods.
See the video Intro to C# in Godot 3.1: Your First Script (tutorial) by GDQuest.
I'll also recommend the underrated video Godot C# Delegate Tutorial.
And hare some YouTube channels have some C# Godot content that I've found: FinePointCGI, BurgZerg Arcade, Abdullah, BeIndie - Alan Thorn, Godot Academy.
Some advice for Unity developers arriving to Godot
Since you are familiar with C#, go ahead and use C#.
By the way my personal recommendation is to use an external editor (such as Visual Studio or Visual Studio Code, for which there are some good plugins for Godot) instead of using the integrated one. Because - even thought C# is fully supported - C# is poorly integrated with the editor.
Also be aware it is OK to use both C# and GDScript on the same project, or Godot visual scripting, or other languages that can be added to Godot (or even C++ if you really want to). How much C# you use is up to you.
Thus, you can use each language to their strength. For example you can use C# to get some extra performance compared to GDScript, and have access to all the .NET libraries and some modern language features. And use GDScript as glue with the rest of Godot (e.g. exporting variables and connecting singals, and calling into C#).
If you decide to combine GDScript and C# be aware the GDScript cannot properly consume C# async methods. My advice for that is to design around signals when they need to interact asynchronously.
Before you ask how to use components. There are multiple ways to build a component system on top of Godot, but it does not include one. And you probably don't need them. Most of what Unity does with components is done in Godot with Nodes instead.
Furthermore, coming from Unity, you might be expecting some distinction between "prefab", "scene" and "node". There isn't. An scene can have other scenes inside, and the scenes are nodes. And as I said, you will use nodes instead of components.
That does not mean that everything is nodes. You absolutely can make classes that are not nodes. It can be in particular useful to make resource classes, but that is its own topic.
Although, scenes are nodes, there is an slight distinction: a scene is a node that is serialized. Thus if you want to create a whole thing that can be instantiated multiple times, then you want to create a scene. And then you can add that scene as a node - which it is - inside of another scene. Similarly when you import model that you can place in a scene… the models are scenes.
There is an example of loading and instantiating a scene:
var scene = (PackedScene)ResourceLoader.Load("res://scenes/Scene.tscn");
Node scene_instance = ground.Instance();
AddChild(scene_instance);
I don't know if that is what you are trying to do with your code, but I figured I'd mention it, just in case.
Are you looking for an asset store. Godot does not have an asset store, because it sells you nothing. Instead it has an asset library, that you can access from the "AssetLib" button at the top of the editor. To reiterate, everything there is free, it sells you nothing. If you want some comercial assets, you will have to find them elsewhere.
Which reminds me, the preferred format for 3D models in Godot is GLTF (which is an open standard - not a proprietary format like some others).
Godot has a way
Some times when people go from one tool to another they try to stick to how they used the old tool. For an easy example, you don't need to make complex math to position an object relative to another, you just make it a child… But if you can't make it a child? There is RemoteTransform node that can do that. No code involved.
Godot is full of features hiding just below the surface, and there is value in discovering them. And if you are struggling with something, perhaps there is a Godot way. And if there isn't, it can be added.
I'll tell you one that is particularly powerful: the AnimationPlayer node can animate any exported property. In fact, it can call methods. It can also start animations in other AnimationPlayers.
By the way, it goes without saying, but: for whatever code you find online, try to understand the reasoning behind it. It will save you trouble when it does not work and you have to figure out how to fix it.
The base node class is invisible (gray) so you cannot see if they were added or not. You can switch from the local to the remote tab in the scene tree while running to see only one invisible node added.
If you change the code to AddChild(copynode).Duplicate(); you can see it adds all 5 invisible nodes.
I've found a script and am trying to add the script to an empty game object in Unity3D.
From what I've read on stack & the documentation,
"The class name and file name must be the same to enable the script
component to be attached to a GameObject"
As far as I can tell, the script name, game object name and public class within the script file are all named "VRDraw" (see screenshot).
Does anyone know what I am doing wrong here?
(I've also tried deleting and re-creating the scripts/game objects with the proper name from the start, but this didn't work unfortunately)
Also, I can't find OVRAvatarLogger anywhere in the script. Does anyone know where this comes from?
you have another error in your script, fix all errors in your script and unity will recompile all files, so you can add your script to game object
If you notice the red letter on the bottom of the Unity app, you can see a compilation/syntax error, regarding the namespace "Enums".
This might prohibit the IDE from continuing to "work" on your script and attaching it, since it does not pass the syntax check.
Make sure you resolve the reference error first, and then try to re-compile and "play"
I have lost my Unity project which was located on my hard drive. Fortunately, I have found some files that were associated with my project. See here.
Now, I have successfully converted Assembly-CSharp.dll into equivalent C# with a .NET Reflector but I can't find a way to rebuild my Unity project... (or at least a good part of it) How can I do this? Logically, the files that I have now are all we need to recreate the project.
Thank you for your help.
Please comment below if you wish the files to be uploaded.
My original Unity project (which I worked on for a few months) does transitions between menus, by touching, swiping, flicking, or pressing arrow buttons.
.NET Reflector: http://www.red-gate.com/products/dotnet-development/reflector/
You can recover all your scripts if you have the Assembly DLL, but nothing more. All the scenes, images, fonts, models, etc... are gone.
If anything, you can try decompiling the assets files and maybe you can recover some of those. For that you'll need special decompiling tools, such as disunity.
It's an experimental tool and has not been updated a lot since Unity 5 came out, but you can give it a try and maybe recover some files from your project.
Good luck with it !
The answer: NO. You simply cannot do this.
Unfortunately, I know this from experience. I ended up having my programming team hard-code values and have scripts programmatically attached to game objects in case the project was corrupted, so I COULD simply drag the scripts back into a new project and be half way there. It's a hard lesson learned.
I have been using vs2013 for my Unity game with VS Unity plug-in.
Intellisense is working just fine except for my partial classes.
For some reasons that I cannot fathom, Intellisense's complete word function does not work.
If I write down the whole method/variable, it does not show any errors BUT when I'm half done with my typing, it shows up on very rare occasions.
I am currently wondering what may be the cause of this problem but not even close to finding one reason.
Could be that my partial class (split into 2) is large since both added up contains more than 20000 lines (which is the reason I split them).
But then, its merely 20,000 lines of code and is just a medium sized project compared to what other projects may contain.
Any help would be appreciated.
About 2 years ago I worked on a C# project, using MonoDevelop V1 and later V2 (beta release, compiled from source, what a mission) under Fedora. The project went dead. Now I am bringing it back to life, but I have changed my development platform to Debian (testing, i.e. squeeze), which has MonoDevelop V2.2.
I am mostly very pleased with the features of V2.2, but I have a nasty little problem. All the code compiles OK, but at the end of the compilation run I am left with lots of warnings as in the subject line. Obviously, as soon as I try and run the application, I get exceptions left, right and center when I open anything that uses these widgets.
The funny thing is that the library containing the widgets compiles just fine. But somehow these widgets (it's not all of them, only one or two) don't get exposed on the interface, and then subsequent dialogs or windows using them throw the above warning.
Has anybody had this problem? I have googled this and all that comes up is Michael Hutchinson throwing his hands in the air and saying "sorry, can't help here". I really need a fix for this, otherwise I will have to rewrite substantial chunks of code from scratch.
I would recommend trying MonoDevelop 2.4, but in any case here are some hints.
If you have an assembly which uses custom widgets implemented in the same assembly, you may be having a chicken-egg problem, since MonoDevelop needs the built assembly in order to find the custom widgets, but that's the assembly you are trying to build. This problem can be easily solved by building again the project after you get the warnings you reported. Beware, you have to build, not rebuild, since rebuild will delete the assembly and you'll hit the same problem again.
If you are not having the above problem, or if the solution doesn't work, the problem may be that the objects.xml file that contains the information about the exported widgets is not properly updated. You'll find that file in the project that implements the custom widgets, in a hidden gtk-gui folder. Open the file and check if the all the custom widgets are declared there. If a widget is missing, try opening the source code file of the widget and do a small change (e.g. a whitespace change) and then build the project again. MonoDevelop should be properly updating the file.
If you are still having trouble, please file a bug report.
I think I found a way out. Not sure whether this is the "official" method, but it seems to work.
In this library a normal widget's class definition starts like this:
namespace Amino.Common
{
//! A text entry combined with a pop-up date selector, very useful for otherwise busy dialogs
public class DatePicker : Gtk.Bin
{
If I now add two additional declarations right in front of the class statement, like this:
namespace Amino.Common
{
//! A text entry combined with a pop-up date selector, very useful for otherwise busy dialogs
[System.ComponentModel.Category("Common")]
[System.ComponentModel.ToolboxItem(true)]
public class DatePicker : Gtk.Bin
{
then
That widget gets included in the objects.xml file and
The entire solution compiles as expected (and runs as expected).
Maybe somebody could shed some additional light on this, I would love to understand this better.