error CS1501: No overload for method 'Instantiate' takes '4' arguments
Hi all,
I'm having what is, as far as I can tell, an issue with Unity Cloud Build. The following code compiles fine on my computer and in the editor, but fails with the error in the title when I try to build it in Cloud Build. According to the API documentation, this is a valid construction of Instantiate
, as is the 2-parameter Instantiate(GameObject go, Transform tf)
(which also fails in Unity Cloud Build).
Does anyone have any advice, or should I simply avoid Cloud Build for now?
Thanks in advance!
Edit: I should clarify that GameState.Instance.RemarkObject
is a GameObject
from a Prefab loaded into GameState
through the editor.
using UnityEngine;
namespace Base
{
public abstract class Entity : Actionable
{
public void Remark(string remark)
{
GameObject rmk = Instantiate(GameState.Instance.RemarkObject,
transform.position, Quaternion.identity, transform);
rmk.GetComponent<TextMesh>().text = remark;
}
}
}
Answer by Hellium · Mar 03, 2017 at 09:13 AM
Simply do this instead :
GameObject rmk = Instantiate(GameState.Instance.RemarkObject,
transform.position, Quaternion.identity);
rmk.GetComponent<Transform>().SetParent( transform ) ;
rmk.GetComponent<TextMesh>().text = remark;
This worked! Thanks! I'm curious as to why what I did is in the Script Reference when it causes a compiler error on Cloud Build, and why it works in Unity and not in Cloud Build.