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.
Related
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.
I am here because I have a program and some features in my mind.
But I am not sure what these features are called in programming terms. So I am unable to even do a proper google search regarding the same. I am keen to identify what this is called, so I can progress my Analysis and Research.
I have developed a program, with C# and Windows Forms. Currently it interfaces with YouTube API and monitors the chat. I am also raising some events, when chat messages arrive and when the message follows a certain format/syntax. Everything is working fine so far.
What I want to do is:
If someone using my software, who has access to just the binaries. But want to write their own logic, which handles some of the events I am raising. How do they do that?
I want the user to write their own program/class, put it in a specific folder. I will expect it to have a Start() and End() method. Inside the methods, they can write the code to subscribe to any event of their choice and do what they need to.
I already have written code inside my main loop, which will loop through the folder which is supposed to contain the user programs, and tries to invoke the Start/End method of their programs/classes.
For me, as the original author of the project, I can just go ahead and start writing the code inside the folder. Once I build and execute. Everything works fine. The main program triggers the Start/End inside the program/class that I added. And the events are also handled fine.
But how about someone using my software, who wants to handle it's events, without having to re-compile my code. How do they do that?
You have the following options
Option 1
Create a template project with all required references and a code file (.cs) with the Start() / End() methods.
Add comments to the start() / end() methods or add a code sample of how they can work with the additional events.
The project should compile fine without any source code for your main project.
If you expect the users to use Visual Studio Code, give them instructions to compile using VS code.
If they are going to use any text editor, you need to provide them with a msbuild command line to compile their code.
Finally they can put the .cs code file in the specific folder along with your main project binary and try it out.
Option 2
The above option will work only if your users are also programmers.
If they are semi-techies, you could provide a simpler format for them to provide the additional events.
For example, create a json or xml format where they can specify the event name and how they want to handle it - either a script or choose from some options. For example -
{
"myevents": [
{
"event": "chatUpvote",
"handler": "ThankYouHandler"
},
{
"event": "chatDownvote",
"handler": "TellMeMoreHandler"
}]
}
as the title says, I try to get the local position and rotation values of all parts in an assembly that get moved in a MotionStudy. I'd like to be able to recreate an animation that already exists in SolidWorks in other environments like e.g. Unity. Therefore I need to read the time and transformation values of each keyframe in the MotionStudy.
I've dug through the API but I couldn't find anything promising. I can get access to the MotionStudy object itself, but I can't find valuable information in there. I also tried to get motion features and properties, but the returned objects were not useful at all.
Link to the API section for MotionStudy : SW API MotionStudy
I really hope that someone has already managed to do this.
Thank you.
I'm using Unity and I need a button that calls a function that allows me to build an AssetBundle, so I can make a software external from unity that allows me to build AssetBundle; is it possible?
Thank you all.
Build an AssetBundle runtime
This can not be done. bulding assetbundles requires the buildPipeline which is in the UnityEditor namespace which can not be accessed at runtime as it is editor only.
Making an external application for this that you call from within Unity would most likely also not work unless you know how to replicate their pipeline in your own application, and i doubt you will be able to call it form outside Unity (And even if you could it would still not work at runtime as assets will become read only)
I'm not sure why you would want to build assetbundles at runtime, but the only method i can think of that may work for this would use JSON/XML.
This would need two Instances of unity running to do it in "real time". The first instance of unity would be running your game with the object you want to make into anassetbundle. After clicking your button a function would be called that gets all the information on your GameObject (components, values, ID's, literally everything) and parse it into a XML/JSON file. This file will then be uploaded/saved somewhere where your second Unity instance can access it. The second instance of unity will then read this JSON/XML file in editor time, reconstruct the original GameObject from the data within (This can be done in editor time from script) and then put this reconstructed object through the assetbundle pipeline.
Do take note though that i've never done this myself, and am not 100% it will work. Though i am fairly confident if done correctly it should work.
I'm working with the visual studio 2010 codedUI tests.
I want to be able to perform a little more than i can at the moment.
e.g. I can can Assert if a particular field "AreEqual" to or "Contains" etc, but i want to do more.
eg, i want to check if the field contains a numerical value within it.
I edited the UIMap.Designer.cs and was able to achieve what i wanted.
The only problem is is that this file gets overwritten when new test are added.
so my question is how can i "fiddle" with fields/stings in the UI and implement my own assertions on them?
Thanks
Use the partial class created (UIMap.cs) to add your custom code. This file doesn't get blown away and has full access to the internals of the UIMap (since it's part of it).
You can get it done dude, but be careful by keeping back up.
Open uitest file :
Go to test marker node that contains the relevant assertion,
Delete the method.
Save and find the stuff you expect
Its beeen working great for me but one two occasions I was dumbfound to face many issues with my acriipt running. So have back up and test this out.
I was told that the solution in "Coded UI" was to create your own libraries and then twitch your new test cases accordingly.
Haven't tried it, though.