Hello!
in one of your samples (the door demo) you attach a script automatically on unity, i would like to request a tutorial in how this was achieved so we can learn how to do that in our models.
thank you!
Tutorial request for attaching scripts automatically on unit
6240 8 2- Lune Sparkle
- Member
- 40 posts
- Joined: 12月 2014
- Offline
- damian
- Member
- 402 posts
- Joined: 3月 2013
- Offline
A tutorial would be nice and I'll push that on the agenda but in the mean time here's a quick howto.
It's actually not too bad. You just need a detail string attribute on visible SOP of the object you want to attach the script to.
The attribute has to be called: “Unity_Script”
It has to contain a JSON string that starts with the variable “script” with the value being the name of the Unity script (no .cs). Afterwards, you just name the variables you want to set on that script (on-attach) and their values in the form: “arg#Name”:“<variable_name>”, “arg#Type”:“<type>”, “arg#Value”:“<value>”. The “#” should start with 0 and just increase by 1 for each argument.
Here's the example for the doors asset. Notice the name of the Unity script is “doorAnim” and it's setting the “string” variable “door0” to “door_0”.
{“script”:“doorAnim”, “arg0Name”:“door0”,“arg0Type”:“string”, “arg0Value”:“door_0”, “arg1Name”:“door1”, “arg1Type”:“string”, “arg1Value”:“door_1”, “arg2Name”:“door_width”, “arg2Type”:“float”, “arg2Value”:“1.14999985695”, “arg3Name”:“speed”, “arg3Type”:“float”, “arg3Value”:“1.0”}
Look inside the door demo asset, specifically at the “Control” object to see how this string is assembled.
It's actually not too bad. You just need a detail string attribute on visible SOP of the object you want to attach the script to.
The attribute has to be called: “Unity_Script”
It has to contain a JSON string that starts with the variable “script” with the value being the name of the Unity script (no .cs). Afterwards, you just name the variables you want to set on that script (on-attach) and their values in the form: “arg#Name”:“<variable_name>”, “arg#Type”:“<type>”, “arg#Value”:“<value>”. The “#” should start with 0 and just increase by 1 for each argument.
Here's the example for the doors asset. Notice the name of the Unity script is “doorAnim” and it's setting the “string” variable “door0” to “door_0”.
{“script”:“doorAnim”, “arg0Name”:“door0”,“arg0Type”:“string”, “arg0Value”:“door_0”, “arg1Name”:“door1”, “arg1Type”:“string”, “arg1Value”:“door_1”, “arg2Name”:“door_width”, “arg2Type”:“float”, “arg2Value”:“1.14999985695”, “arg3Name”:“speed”, “arg3Type”:“float”, “arg3Value”:“1.0”}
Look inside the door demo asset, specifically at the “Control” object to see how this string is assembled.
- Lune Sparkle
- Member
- 40 posts
- Joined: 12月 2014
- Offline
- Lune Sparkle
- Member
- 40 posts
- Joined: 12月 2014
- Offline
- damian
- Member
- 402 posts
- Joined: 3月 2013
- Offline
- Lune Sparkle
- Member
- 40 posts
- Joined: 12月 2014
- Offline
Thank you damian!
there is something but i fixed it with a workaround, not sure if it is worth reporting but here it is:
i want to add reaction scripts to colliders created inside houdini, however the script is added to the output game object (sorry for typo in unity), i fixed it at runtime, the script searches for the collider inside the hierarchy and instantiates itself in that game object.
not exactly a bug, but an opinion only. thanks again damian!
there is something but i fixed it with a workaround, not sure if it is worth reporting but here it is:
i want to add reaction scripts to colliders created inside houdini, however the script is added to the output game object (sorry for typo in unity), i fixed it at runtime, the script searches for the collider inside the hierarchy and instantiates itself in that game object.
not exactly a bug, but an opinion only. thanks again damian!
- damian
- Member
- 402 posts
- Joined: 3月 2013
- Offline
For now, your fix seems as good as anything we could come up with.
It's not clear how one might specify in Houdini which “part” of the geo you want the script attached to because those “parts” don't really exist in Houdini. They get created in Houdini Engine and the names are not really reliable.
But it's a good feature request. I'll keep in in mind.
It's not clear how one might specify in Houdini which “part” of the geo you want the script attached to because those “parts” don't really exist in Houdini. They get created in Houdini Engine and the names are not really reliable.
But it's a good feature request. I'll keep in in mind.
- kahuna031
- Member
- 897 posts
- Joined: 7月 2018
- Offline
i fixed it at runtime, the script searches for the collider inside the hierarchy and instantiates itself in that game object.LSparkle: I'd like to do exactly this. Do you mind (or anyone else) showing how this is done in a script? As someone who's used to do these setups inside Houdini, this runtime level of scripting is quite new to me.
Edit: Never mind. Think I'm getting it.
using UnityEngine; using System.Collections; public class inheritBehaviour : MonoBehaviour { // Adds a sphere collider to all children that doesn't have a collider void Start() { print("init" + this.gameObject.name); //print("Components: " + this.gameObject.GetComponents(typeof(GameObject))); int nChildren = this.gameObject.transform.childCount; for (int i = 0; i < nChildren; i++) { GameObject child = this.gameObject.transform.GetChild(i).gameObject; if (child.GetComponent<Collider>()) { // If this game object has a collider, continue print("Collider found on object" + gameObject.name); } else { print("No collider found on object" + gameObject.name); SphereCollider sc = child.AddComponent<SphereCollider>(); //add collider } } } }
Edited by kahuna031 - 2017年2月26日 15:01:48
B.Henriksson, DICE
- Lune Sparkle
- Member
- 40 posts
- Joined: 12月 2014
- Offline
-
- Quick Links