Questions tagged [monobehaviour]
The monobehaviour tag has no summary.
33 questions
0
votes
1
answer
61
views
My scene crashed on `MonoBehaviour::VirtualRedirectTransfer`, how can I figure out which class or GameObject triggered this error
I have a Unity scene that works fine in editor, but always crash after being compiled into an executable with .NET/Mono backend, so I enabled stacktrace logging and dump the whole log into a file:
<...
0
votes
1
answer
242
views
A good way of handling MonoBehaviour initialization in Unity?
Recently, I've been experimenting with different ways of initializing MonoBehaviours (since constructors are not an option), and I reached a solution that I am mostly satisfied with, but there are a ...
1
vote
1
answer
183
views
How to call every method with a certain name from a set of classes in C#
I have the following case:
I have a class called App.cs and here I have a function called Render, that runs once every frame:
...
0
votes
1
answer
1k
views
Does MonoBehaviour have a method that is called in editor when the object is created?
I'm coming from Unreal, and in Unreal you can use the constructor to make logic that is called in editor (as well as when beginning play).
This is useful for some things, but Unity documentation says ...
0
votes
0
answers
42
views
Unity Thought There Was No MonoDevelop In Scripts in My Code
Weird Unity thinks that the code that I've checked already has a MonoDevelop inside of it, but unity doesn't think so, can you help find what I wrote wrong in these two scripts?
...
-1
votes
1
answer
78
views
MonoBehaviour Wouldn't Work [duplicate]
I was writing the character controller for my player character, but Unity said that there was no mono behavior script in the file I'd written the file right and I included the mono behavior ...
0
votes
2
answers
702
views
Initializing Monobehaviour in Unity
I have three scritps and one plain C# class.
EnemyMonobehaviour, EnemyAttackMonobehaviour and UnitState plain class.
In enemyMono I have Initialize function that initializes unitState.
...
0
votes
1
answer
104
views
Pattern for scripts that should only update when in trigger range
I have a script that triggers when the enemies are in range of my objective, but it also contains an Update method for its the damage.
I noticed that Update is being called even when the enemies are ...
0
votes
1
answer
4k
views
Gameobject does not derive from MonoBehaviour
I am trying to put a gameobject into a prefab.
Unity says "You are trying to save a Prefab that contains the script 'NPCDebugInfo', which does not derive from MonoBehaviour. This is not allowed.
...
1
vote
1
answer
342
views
How to connect the Data Layer (Models) with the Visual/Interactive Layer (MonoBehaviours)?
I have been struggling with this dilemma for quite a while already.
Our game is complex enough that we have tons of logic in normal C# scripts that function very independently of any Unity specific ...
0
votes
0
answers
150
views
How to create same paradigm of monobehaviour and processing in C++
Having worked with monobehaviour and processing before, is it possible to create the same paradigm both frameworks use which basically is writing all code in two main functions, start/setup and update/...
0
votes
1
answer
1k
views
Two Colliders on the same GameObject for different purposes
I'm somewhat new to Unity and am trying to build a battle system.
Right now, I have an attack that checks collisions with enemy objects like this:
...
0
votes
1
answer
582
views
How to call StartCourotine in abstract class?
Bellow is my code. I have an abstract class and a inheriting class. This keeps giving me an NullReferenceException, on the ...
2
votes
1
answer
682
views
How to subscribe for events for easy unit testing?
I've run into the same problem multiple times that is begging for a solution. I try to write a lot of decoupled code to make my MonoBehaviour scripts as reusable as possible. This means that I end up ...
0
votes
0
answers
844
views
Unity - Which is more optimal persisting between scenes? `DontDestroyOnLoad` or `LoadSceneMode.Additive` [duplicate]
User philip previously marked this as a duplicate question of this, but failed to actually read either question it seems. The question that this was marked as a duplicate of, does not address the ...
3
votes
1
answer
2k
views
How to reference nameof private serialized field in unity custom inspector
I'm running into a problem that I think will seriously affect maintainability down the road, so I'd like to figure it out now before it becomes a problem.
I've been starting to use private [...
-1
votes
1
answer
63
views
Public MonoBehavior string fields empty
This is bizarre enough that it has to be me being an idiot.
I have a MonoBehaviour with some public fields and public methods:
...
1
vote
1
answer
195
views
Unity, WaitUntil in a self-made message box class
I managed to make a simple message box prefab with a Text and a Button through Canvas, and ...
-1
votes
1
answer
551
views
How do I convert an interface into a MonoBehavior in Unity?
In my method iTest.doStuff(), I try to convert interface testInterf _ti into a MonoBehavior. This gives me "error CS0246: The type or namespace name 'MonoBehavior' could not be found", but in the ...
1
vote
0
answers
38
views
Unity, weird error appearing after playing in editor
got a bit of a weird error, hopefully someone here can help.
So I have created a custom class (does not derive from Monobehavior).
Then I have a variable for the class, in the Start() method I set ...
0
votes
1
answer
1k
views
Is it efficient to have a only-data MonoBehaviours on lots of game objects?
I'm working on a voxel based game and this solution would make the implementation of networking and other features a lot more easier, it is less error-prone, easier to edit in the Editor, etc.
So the ...
0
votes
3
answers
120
views
Public value null after assigning it from a different script
Hello I am a beginner in Unity and still currently exploring with scripts.
So I ran into a problem.
In FetchAndAssign.cs Script
...
1
vote
1
answer
2k
views
Waiting for object's Awake() after loading a new scene synchronously
I have a GameScene with an initially active GameObject in it, which has a singleton component:
...
8
votes
1
answer
4k
views
Unity Hybrid ECS with "old way"
Is it possible to use Hybrid ECS with some components and the standard MonoBehaviour with all your old code?
I want to know because I already have some game ...
-1
votes
1
answer
272
views
Unity3D MonoBehaviour in .dll loses serialized data when dll is updated
I have a MonoBehaviour class in a compiled DLL that I have included in my Unity project. It automatically serializes public field data as expected. However, whenever I update the dll (by overwriting ...
0
votes
0
answers
113
views
Capture Video without Third Party SDK's
I am trying to capture the game play and store it on local memory without using any third party sdk's. I tried This Video Capture Script but i didn't get the recorded file even i don't know whether it'...
0
votes
1
answer
182
views
few button image are not updating
I am working on a game that contain 1000+ buttons starts from 0 - 999 with 3 decimals like 0-9, 00-99 and 000-999. if the user click the button the button image want to change. it working fine for me ...
0
votes
0
answers
319
views
Best practice to define fields scope in C# script of Unity in regard to serialization?
I know from Object Oriented Design perspective that in order to provide encapsulation, we should avoid defining ...
2
votes
2
answers
3k
views
How can I give a MonoBehaviour field a default value that depends on the object?
In Unity3D, I have a MonoBehaviour which gets added to game objects. I'm adding a string "name" field to it. I'd like the ...
1
vote
2
answers
9k
views
How to make Lists (and Arrays) in Unity only take GameObjects of a certain "type"
If I were coding in generic C# I can create a list that only stores a certain type of object. If I accidentally try to add anything other than that type to the list I will be promptly told and can fix ...
1
vote
1
answer
771
views
StartCoroutine from other MonoBehaviour is not working
I am trying to replicate the model of Unity documentation about coroutines, but I want to partition it in another class:
I have these two:
...
1
vote
1
answer
1k
views
What is the difference between a game object being disabled and it made inactive?
I am looking over a script that has a particular function called to disable the script and mark a list for re-structuring:
...
0
votes
1
answer
253
views
Have several classes with a common interface, but still able to access MonoBehaviour methods through that interface?
In our project we used to have a PlayerObject class and then Unit and Building derived from that class. We recently started taking a look at Bolt, which requires classes that define objects that may ...