Monobehaviour Update not working in namespace
I've read in a few places that monobehaviour should work inside new namespaces, but i currently cannot get Start/Update and so on to work inside a name space while it is not giving me any errors for attaching it to the script. The test script:
using UnityEngine;
using System.Collections;
namespace aNameSpace
{
public class ansTest : MonoBehaviour
{
// Show Debug info
private bool debug = true;
public ansTest()
{
Debug.Log("test");
}
//
void Update()
{
if (debug)
Debug.Log("Updated");
}
}
}
In this, the object being created outside the name space Test is submitted to console but not Updated.
Answer by ThePersister · Nov 15, 2016 at 03:00 PM
Hi @Kennyist,
This code ran fine for me:
using UnityEngine;
using System.Collections;
namespace aNameSpace
{
public class Test : MonoBehaviour
{
private bool debug = true;
void Update()
{
if( debug )
Debug.Log( "TEST" );
}
}
}
The only thing I can imagine, although it's silly, is that you didn't attach the monoBehaviour to any gameObject in the scene. For Monobehaviour code to run, it must be active in the scene. If you know it's on a gameObject, check whether the gameObject as well as the script are enabled.
And if that doesn't work, like @tanoshimi mentioned, remove the dneTime constructor or add void, but since you're not getting any errors, it's probably the former.
I hope that helps out. If not, share more details and I'd be happy to help. If it did, please accept this answer, it'd be much appreciated! Have a nice day :)
Ah you are right, i was creating the object via a script attached to an object but doing it as require component fixed the issue.
Answer by tanoshimi · Nov 15, 2016 at 02:52 PM
That code will not compile because dneTIme() doesn't specify a return type. But if you correct that by changing line 12 to
public void dneTime()
You'll find it works fine.
Ah, an error while editing down the code to paste here. Changing still didn't work.
Your answer
Follow this Question
Related Questions
Access script from a namespace 1 Answer
NameSpace player health 1 Answer
A namespace cannot directly contain mambers such as fields or methods... 2 Answers
Namespace inside DLL file 0 Answers