#💻┃code-beginner
1 messages · Page 550 of 1
If you have to do that, you're doing it wrong.
but the larger context you were using it in was that they thought it was ridiculous to have to do extra to do something so simple. The response that you could write code to write that code that should be default for you doesn't hold up imo
the base argument here is people shouldn't have to reinvent the wheel by creating functionality that should be default
so because they wanted it to already exist means my response of saying that it is easy enough to implement yourself is invalid? next time i'll just say "that is impossible because it isn't in unity already"
if you're so fussed about this feature not already existing in unity, then go suggest it on the roadmap. complaining that it doesn't already exist is not productive.
Writing something that just spits out a function that does GetComponent calls is definitely on the lower end of difficulty
okay well ANYWAYS
https://github.com/OranBar/AutoAttribute-for-Unity3d I've used this in the past and it worked pretty well
And most of the finicky annoying things to handle probably won't pop up in most code
You could use the undocumented __internalAwake callback to avoid needing to call it yourself or preventing the user from defining an Awake callback as well
no no no, you see, it doesn't exist in unity. and someone else already made it. so suggesting to someone that they possibly learn to do it theirself "doesn't hold up"
Can we stop the belittlement of correctness going on in here? If unity doesn't have the feature, suggest it on their roadmap.
Thank you.
How to deal with custom global settings in c# that need to be set before other classes can use it?
For example let's say that I have MyScript.cs and GlobalConfig.cs and I need Awake method of GlobalConfig called before MyScript because it needs properties of GlobalConfig.
Awake is used for setting internal references/data. Start is used for setting external references/data . . .
there is no way to determine the order Awake is called for a script . . .
technically you can set the script execution order, but if you're relying on that for your own code then you are gonna have a bad time
you can also set the script execution order, but it's not something you should rely on . . .
so how can I reference one script in another in a way that I can use it fully?
I mean you could technically encapsulate the contents of the awake method inside an IEnumerator with a slight delay on top of the method but i’m not sure if that’s good practice in the long run
I've heard that I can set execution order of .cs scripts in project settings but that' a horrible idea, I want to use dependencies out of the box
in Godot I have a entry point script where I can set everything and prepare my scene by hand
in Unity... I don't have such control (probably)
huh? if you reference a script, you have access to all of its public members. it's always "fully"—if that's what you mean. there are many ways to get a reference: search by tag, use Find methods (not really recommended), or GetComponent . . .
oh, you can also make GlobalSettings a singleton if only one instance of it needs to exist . . .
I already have a GlobalConfig singleton
Another idea would be to have two scripts on separate game object, with the one being called first on an active gameobject and the other on an inactive gameobject and set the inactive gameobject to active after a few milliseconds since your code won’t execute on inactive objects
but I can't depend on it because I have no guarantee that its properties are initialized
Then make sure they are?
as i stated at the beginning. Awake runs before Start. just place the code for your other script in Start instead of Awake . . .
I don't use Start at all 😉 I want to access GlobalConfig in Awake
you should never use values (data) from anothe inside of Awake as it's mainly used to intialize internal values on the script itself . . .
Start is used to grab external references and use their data because it will be initialized by then . . .
but there are global settings common for all scripts and I need them in all Awake methods in all scripts
why not? that's the solution and normal. it's common practice . . .
it ensures initialization order . . .
why can you not just use Start for that?
I won't set myVar to 1 for every script I have... instead I want to have a GlobalConfig with myVar and control this property in one place
what is being set in GlobalSettings that you call in Awake?
potentially more than 100 different global options for my game that need to be set before any other script in awaken
to clarify, are you just assigning values to variables? can you post the script. this seems more of an architecture/setup issue . . .
again, why can you not just use Start to access that GlobalSettings object instead of Awake? why must this access happen in Awake
because I want to access global settings before the first frame happens
there are values that need to be initialized and Start is not for initialization afaik
Then use OnEnable..
Start is for initialization. it just happens after Awake but before any Update runs
which is precisely why it is primarily used to access other objects
this will work as well, but just like Start, it's called after Awake. apparently, they have issue with that . . .
I believe OnEnable is called before Awake
nope . . .
OnEnable is called after Awake, but it is not guaranteed to be called after another object's Awake
It’s the first thing that gets called when the script is activated in your scene, no?
Awake is the first . . .
- Awake
- OnEnable
- Reset
- Start
Ah, I see thanks for letting me know
hmmm okay so I should use Awake ONLY for local config and then if I want to depend on some class I use it in Start so that I'm sure my dependency is initialized
Yes, but Awake is always called first . . .
that makes sense
Boxfriend literally linked a page that explains it:
<#💻┃code-beginner message>
haha, boyfriend, i like that one . . .
yes, that is what you were instructed earlier #💻┃code-beginner message
Yes, I didn’t look into the documentation you’re right
Phone auto completion...
nah, it's cool. i'd have left it. adds flavor . . . 😏
I'm not sure boxfriend would appreciate that lol
sometimes i forget that my username would normally autocorrect to that. i've been using it for more than a decade now so my phone has recognized it for a very long time. it is pretty funny to see it happen in the wild though
that was literally my first response to your question . . .
Member on Steam since 2009, pretty legit lol
@junior ivy also, i was asking to see the script to check what type of values you're setting. if it's just assigning simple data, you can use an SO and reference that for any script that needs it . . .
I thought that I can't initialize things in Start because it's already a first frame
i'm not sure why; Start is called before the first frame update . . .
It does. But before the first frame is rendered.
There's no such thing as 0 frame
Awake is called in the first frame as well
It's even in the default template :p
0 frame does not exist. there has to be 1. it's just the start of it, so technically, before anything else . . .
I don't remember if Time.frameCount starts from 0 or 1 🤔 I think 0
if I imagine it in a low level, then it must be before the main loop so pretty much before the first frame
Why? What is it in your game that would require that?
And while we're at that, Awake is called within the main loop.
either way, this doesn't affect you or what you're trying to do . . .
there are multiple ways to create an order of initialization that you can do. just pick one and test it . . .
Both of them initialize but the Awake method is called even when the object is disabled so use Awake for critical initialization such as object references, etc, then use Start for scene specific initializations
weird because it means the main loop has to do at least one check on each iteration instead of initializing before the main loop
Not sure what you mean by that. What check?
You mean calling awake? Well, yes. How do you expect to initialize newly loaded gameObjects and scenes in the middle of the game(when the main loop is already running) then?
well I imagine that Awake is called for all scripts for all scenes that aren't even loaded
maybe bad assumption
Indeed. How can it be called on something that doesn't even exist?
why? how can it call Awake in an unloaded scene (means it doesn't exist) on a GameObject that is not loaded (also doesn't exist) . . .
because I thought Awake it not related to scene loading or creation of base game objects
I thought awaking is a process called before all of that for all scripts in the project
Nah. That would be crazy.
Yes but you have to be in that scene. Imagine 300+ scenes running at once, you’ll crash lol
nothing is called on project scripts directly, they have to be added to gameobjects in scenes
when the scene exists, gameobjects exist, and then their components exist
awake is called on each component
Awake is part of a script's lifecycle. Scripts — MB classes — are attached to GameObjects, therefore, they are tied to the GameObject . . .
well not running but you would only initialize them, shouldn't be a problem in less than few thousands (depending on what is really going on under the hood ofc)
it would have quite a bit of overhead
there's a ton of scripts just in UnityEngine
also this doesn't make sense within the context of OOP, so maybe you should brush up on that
none of this affects what they originally wanted to do. that was already answered. at this point, they (seem) to be grasping at issues or looking for inadequacies . . .
Anyone know why my unity project sometimes gets stuck on reloading domain forever and i have to close it in task manager? I've had this happen twice so far and it sucks
ouch, that's not cool. are you waiting for many changes, or just simple code fixes?
just simple code fixes
i had it happen for the first time at the very start after i updated my project to unity 6
and then it just happened again a second ago
has to be unity 6 issues. i would check if other people experience the same thing. maybe the forums?
ok
yea I've never experienced anything like that on any of my projects before this so that's probably the issue
Do you know if this is a good starting point so far for the survival resource node system i was trying to work on earlier, i decided to not do the scriptable object part just yet until i understand it a bit more, but this is what i have done so far https://paste.ofcode.org/LrDSfh8YRXypTWb7xfAc4d https://paste.ofcode.org/cBG644QjEDNFRqjYt9HVD9
I currently just have one monobehaviour script that is on both of my ore node types and is being accessed by the playerhit script on my player which when hit by a raycast triggers the DamageNode() Method which lowers the health by the damage amount
once the health is 0 on the ore
it triggers a new method called DropItems() and spawns in how many items are set to spawn in the inspector which are just prefabs of a cube with a rigid body for now dragged into the inspector as a reference
not really sure if this is good or not, any feedback would be appreciated
Might be able to see where it's stuck by attaching the debugger to the process and breaking.
It's a good start.
How do I do that also is that something I have to do before it happens so if it happens again then I can see why?
You'll need to learn how to use your ide debugger first. There are plenty of resources on that online.
Once you know how to work with it, just attach to the editor process and press the break all(pause) button. Then you can see the callstack of the current thread and switch between threads.
The details are too much to explain in discord. You'll need to learn it on your own. But feel free to ask if you have specific questions.
Ok cool thx
Do u have any tips/feedback on how to make it better/more modular
Learn how to use scriptable objects. Other than that, you'll need to explain what exactly you want to be modular.
One advice I can give is:
Don't try to make a perfect system right away. You're developing this system for the sake of your project, not the other way around.
When you start working on a feature that the current implementation does not allow, think of how you can refactor/modify it such that this and other similar features would be implemented with ease.
Basically, this should be your workflow:
Feature required -> does the system allow for such a feature? -> if not, extend the implementation
Wrong approach:
??? -> how to make it more modular
Ok thanks
quick and simple question
is it not posable to instantiate in a class variable. I might have asked this questions a couple of years ago I don't remember.
All one Example Code:
using UnityEngine;
//==== Main Class ====//
public class Example : MonoBehaviour
{
[SerializeField]// Class Variable
private ExampleClass exampleClass;
[Serilised feld]
private GameObject exampleObj;
void Start()
{
if (exampleClass != null)
{
exampleClass.exampleObj = exampleObj;
exampleClass.ExampleFunc();
}
}
}
//==== Variable Class ====//
[System.Serializable] // To allow customization in the Inspector
public class ExampleClass
{
[SerializeField]
private GameObject exampleObj;
public void ExampleFunc()
{
Instantiate(exampleObj);
}
}
Instantiate is a static method from UnityEngine.Object. you need to access it from the type . . .
How did you come to your conclusion? Did you get an error that might have said whats wrong?
also, it has nothing to do with calling it from a field (class variable), but from a C# class instead of a MonoBehaviour . . .
a C# class has no concept of Unity or where Instantiate came from . . .
Thank you @cosmic dagger You were right. It needed MonoBehaviour. I was worried that adding MonoBehaviour would not work or might break it, but that was exactly what it needed to work.
ExampleClass class is not the same as Example class
I don't know why i thought that the ExampleClass variable would pull from Example classMonoBehaviour
And adding a monobehaviour should be treated as a component, so added not instantiated
<@&502884371011731486>
In an RPG type game in order to show the different maps (cities,plains,castles) is it all done in the same scene but changing the tilemap or is it done in any other way?
how do i change variables from one script in another?
on left click im casting a ray which can detect if it hit an enemy but when it hits i want it to change the enemy's health variable
The RaycastHit you get has a reference to the other transform/collider. You can call GetComponent on those component references to get other components on the gameobject.
Either way is fine. How people would end up leaning depends on a lot of details regarding overall project structure.
but the game is designed to have hundreds of enemies
do i have to reference to them all..
is there a way to do it with tags?
You don't have to hold on to the references, just temporarily use the ones the physics system is handing to you
how do i assign both of these to the same property? doesnt make sence
tmpColorTitle.fontStyle = FontStyles.Normal FontStyles.UpperCase;
https://unity.huh.how/bitmasks#combining-masks look at the second example which uses an enum
maybe someone can help me: why are backfaces grey and not white? (no settings changed in the material). the faces turn as i click them.
Because they're back faces. Probably having the normal facing down(since it's the back of the front face). You'll either need a custom shader that somehow accounts for that or just make a mesh with double faces.
If you don't care about lighting, use an unlit shader and there would be no difference.
i see. changing the direction of the normals should fix this issue, right?
how can I detect if my player collides with something?
Thanks 🙂
It would fix the back faces, but it would cause the same problem for front faces.
does Start() within monobehavior of a GameObject I just spawned on a frame runs at the same frame?
Start will be called in the first valid frame when the object becomes enabled. Which means the first frame on scene load and the same frame on object creation/instantiation.
Source, a copy paste from this thread: https://discussions.unity.com/t/awake-and-start-frame-execution/724191
cool, thanks
hi! i m with unity tests, for some reason i cant find a way to start it in my pacman, i think is because i cant instantiate it...
could i ask for some help? !code correctly please twt
i m trying in playmode rn
yeah, unit test are awful xp
What does "I can't find a way to start it in my pacman" mean?
Also, a tiny !code snippet doesn't give any context share everything related please
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
What are you testing, just curious
i just want to inicializate the elements in the unit test
i add the getcomponent in differentes elements
this is my setup for the test
i segmented ghost and pacman in two, i want to create the objects
this is a playtest of the ghost
What is the actual issue?
Please properly share the !code instead of cut screenshots, and explain what the actual issue is
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Because right now the answer to "i just want to inicializate the elements in the unit test" is "just do it"
It should work fine. If it doesn't work then check if the code is executed at all
okay, lemme try
heres the playtest, ghost and the createObject, which seems to me that it doesnt initialise
You are doing new Ghost() which is invalid
Ghost is a MonoBehaviour, you shouldn't use constructors with those
Nvm It's an array of Ghost[] 🤦♂️
Trying to think of an elegant way to execute code when the value of an enum changes, with different functions called depending on what the value was changed to. Right now my best idea is just putting a big ol' switch into the setter. Is there a better way to do this?
This is the proper way to notify of value changes
Alternatively, if the aim is just to notify of a single value or event, use the event pattern or UnityEvent
How should I decide whether to make a new class derive from MonoBehaviour or not?
For instance, my Garden tool has a component that defines the rectangle the garden exists inside.
There's no actual reason why that Rectangle component needs to derive from MonoBehaviour, but at the same time, theres no reason why it couldnt be a Mono class
It derives from MonoBehaviour when it relies on hooking onto the Unity lifecycle
sure, but as my Garden already is part of the lifecycle, and my Garden is the actual main thing that runs everything, theres no real need for my gardens components themselves need to be in the lifecycle
I could give my Rectangle class its own Update function, then when Garden updates I can call Rectangle.Update myself
Perhaps you should also consider if your classes must be part of Unity's base classes anyway. If you don't use Unity features such as instantiating or otherwise hooking onto gameobjects, maybe you can make a basic class.
Generally I do advice that you have a smart parent component with dumb child components that just listen to the parent and send events to it. If you want a proper hierarchy the child should generally not do anything
is an object data type good to use in general?
article is a bit old, but should help you decide 🙂
https://unity.com/blog/engine-platform/10000-update-calls
speed/optimisation isnt a concern
What is an object data type? Please give more context
Json related?
the biggest differences are probably in performance and usage pattern
if everything inherits from MB (or similar) you're always going to have inherited fields that are possibly unused
for MBs you need to Instantiate and then setup the object somehow, with POCOs you have the constructor
guy can anyone tell me the diffrent betwen
"GetComponent<Rigidbody>().linearVelocity = Vector3.up * jumpHight;"
and
"myRigidbody.velocity = Vector2.up * jumpHight"
i know it make player jump but what the diffrent?
I personally enjoy decoupling everything I can from MBs
like a object someVariable; as oppose to any generic data types in c# or unity. I've seen it on some codes and from what I can tell the object data type can represent anything
additionally MBs are bound to hierarchy lifetimes, POCOs not necessarily
It can. If you are able to use generic types then you should prioritize using it over objects due to boxing (
). Also, you can use a base class for more specific types where you might use polymorphism and use different inherited classes
Generally you don't need object. If a method can return multiple values you should probably use a generic type with a generic constraint. If you have a variable that can represent multiple values, you should look into base classes
And if neither are applicable, object is also completely fine, but you should definitely do some pattern matching to determine the correct type.
its the layout of my Garden tool thats the issue.
Garden will be my MonoBehaviour and for all intents and purposes, Garden is the actual GameObject.
Then the Components are all used by the Garden to produce the final result.
As Garden is definitely a MB, that sort of removes the need for its components to also be MB
ohh okay okay, so use it sparingly as possible thanks for the clarification!
the first example gets the Rigidbody component to access linearVelocity
the second example uses a Rigidbody variable to access linearVelocity
the difference is the first example calls GetComponent, and the second example uses a component reference. the second version is preferred as it avoids calling GetComponent every time you need to access the Rigidbody component . . .
i also have other question. what is vector2 and vector3?
object is not preferred as it will (most likely) involve boxing to convert the data to the intended type . . .
i just type it and dont understand what it mean
these are very simple. you can actually look up using the unity !docs. they have information on all of their API classes with a definition and example . . .
thank
yeah that's what I noticed as well, I really wouldn't go through the hassle of converting it to the correct data type either
It's not a bad thing, but you have the boxing which is defenitely something to avoid
But unless you introduce variables that get a lot of boxing (like each frame), you probably should not worry about it
i'd question why you need to use object in the first place. the data type itself should suffice or T for generics . . .
I just saw it while looking up on something, it's actually the first time I ever encounter of the data type
Yeah so it definitely depends
Even better, if this is with Json for example you might even want to consider using JObject
This can be anything, doesn't need a base class, but also prevents boxing I believe?
it's always good to know what exists. i mean, it is the base type of all C# objects . . .
I think it still boxes, but it is more flexible over object
boxing happens when you treat a value type as a reference type, like casting Vector3 to object
using a JObject to wrap a Vector3 will still create a reference type containing the value type, so no victory there
if you're only dealing with reference type there wont be boxing anyway
Regardless you'd allocate the JObject anyway, so even if there was no boxing it made no difference
Still, a thinn to think of in terms of flexibility
if a parent is disabled, will that call ondisable on the children too?
time to open up unity . . .
If a behaviour's game object is not active in the hierarchy, then it will have OnDisable sent to it
(even if enabled is still true)
I see, thanks
annoyingly, this behavior of behaviours is not described clearly in the documentation
it's implied by the OnDisable example
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/MonoBehaviour.OnDisable.html
// These functions will be called when the attached GameObject
// is toggled.
Why is it telling me its wrong
Its literally the simplist line of code in history
because it's wrong
because it's wrong 😄
Compare your code to examples
HOW 😭
And you bungled it up!
google -> unity input.getkey -> read docs
Have you tried looking at example code to see the right way?
It just says its not valid in the given context
That's not what I said
Have you tried looking at example code?
Example code?
Yes
Like from unity learn?
ok so look at what they did
and look at what you did
they are completely different
Fix yours so it's like theirs
When you are programming you can't just write something that is "sorta similar", it needs to be exact.
Im so sorry i didn't notice the key code
Alright
the parentheses, etc
Let me analyze everything again
Hi im getting a few errors with my 2d space shooter game im trying to make im very new to coding for unity btw
Your IDE (Visual Studio) is not configured for Unity
You need to configure it before you do anything else
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
Why is it telling me its expecting a ";" but when i put it there it underlines the entire code, and what exactly does the ; do (why do we close lines with it) so i understand it for future reference
because else cannot have a condition
Ah huh
Exactly
consider working on it
; is used to end a statement.
Doing my best
Single-line statements are things like...
int x = 123;
Foo();
return 1;
you also have block statements:
{
int x = 1;
x += 1;
x = 5;
}
An if statement runs the next statement only if the condition is true. You often use block statements so that you can do more than one thing!
gotchu thanks man
if (foo)
Foo();
else if (bar)
Bar();
else
Baz();
and
if (foo)
{
Foo();
}
else if (bar)
{
Bar();
}
else
{
Baz();
}
are equivalent
Hi guys i am begginer in unity and c#. Does anyone know how camera for third person in unity should look like, i have my code for camera and movement but i can't make camera rotate how i would like, if anyone can help i would be thankfull
i just installed visual studio code desktop but i cant find it in my package manager on unity?
Unity's Cinemachine package can help you out here
Especially for a third person follow cam -- it has a "Third Person Follow" mode
Your IDE is not visual studio code
you sent screenshots of Visual Studio
Why did you do that
That's a different program
Im glad yall are supportive and patient it means alot to me
i was watching brackeys video on that, and he made camera and player movement in one script, but can i make it in 2 separate scripts?
I don't know what "visual studio code desktop" is
Visual studio and visual studio code are totally different programs
you can do whatever you want! but if you used Cinemachine, you wouldn't be writing code to move the camera
You'd just add a Cinemachine camera and tell it "please follow the player"
oh ok i will try now
so do i delete my camera code?
If you've never used Cinemachine before, make sure you install the 3.0 version
I dunno which one is the default right now
You can hang on to it if you want, but you probably won't need much
oh ok sorry but it seems that my IDE (visual studio) is up to date
ok thanks i will try it now and will tell you later if it works
there is third person aim camera, is that it?
Ok, that's not what the instructions are about though. Read the instructions to set up Visual Studio to work with Unity.
This is how I have my third person camera configured.
Ah, but yeah -- that's what you want!
That'll be pre-configured
You'll want to make it target either the player's root (the object that holds every other player object) or maybe the player's chest bone (if it's human-shaped)
notice how mine targets an object called "Third Person Root"
which is just an empty object parented to my player object
it is just a cube
you are doing God's work man btw this have helped me a lot i just need camera to follow mouse do i do it in code?
i cant seem to find the devenv.exe in my IDE directory?
Can anybody help me? it says :
"'object' does not contain a definition for 'rotation' and no accessible extension method 'rotation' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)"
Is your Visual Studio correctly configured to work with Unity?
Interesting -- this means the IDE things that transform is a System.Object
Can you share the entire script? !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
use paste.ofcode from that bot message
Normally, folks would forget to manually add the Unity workloads - something that you must do yourself during the installation of Visual Studio (you can run the launcher again to just add this modification).
(I'm guessing you have a field named transform higher up)
The bot isn't up-to-date with the changes in #854851968446365696 
where are you looking
It should now be
Use paste sites to post large blocks of code.
https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCam
{
public float sensX;
public float sensY;
public Transform orientation;
float xRotation;
float yRotation;
private object transform;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
//get mouse input
float mouseX = Input.GetAxisRaw("X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
// rotate cam and orientation
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
} ```
this is short enough to just paste inline anyway
so yeah, there's your problem
You have declared a field named transform
its type is object, which is shorthand for System.Object
Remove private object transform;
in my IDE folder in visual studio
sorry if i am bohring to you fen i have added a script to my main camera so it moves with my cursor and it did not work, than i have added debug log to see it in console, and console detects that i am moving my mouse but screen does not move
And make your PlayerCam inherit MonoBehaviour
If you're using Cinemachine now, you'll need to do something to make the Cinemachine Camera look in a different direcetion
the other problem is that this isn't even a MonoBehaviour
notice how your class does not inherit from anything
You've got methods named Start() and Update(), so it sounds like you meant to inherit from MonoBehaviour
ITS FIXXED!
holy shit, yall are so smart
As-is, it's just a "plain old object"
i am using cinemachine and i have set everything how i like but it doesn't move when i move mouse, anyways it does move with my character so i did that good right?
thank you so much
Why do you expect the camera to rotate right now?
is the devenv.exe supposed to be a conf file because thats the only one i can find
cause i have added a code for it to move on main camera or should i add it to cinemachine camera?
Cinemachine controls the main camera
You use Cinemachine Cameras to tell it how to do that
Have a look at the documentation I linked earlier
Show your preference window?
It'll explain how Cinemachine works
It should look something like
How do you put a ≠ sign in c#? I dont have it on my keyboard and iirc there was a sign for it
Looks fine. If your ide isn't configured make sure you added the Unity workload when installing/modifying Visual Studio
If you run the Visual Studio installer again, it'll allow you to modify Visual Studio instead of installing.
!= ?
Let me try that rq
hey, it says my Input Axis X is not setup, do you have a solution?
You probably want "Horizontal" and "Vertical"
i just started coding last night, I only know the bare minimum
yeah
you're currently using the old Input Manager. You can see all of the axis definitions in the project settings
It would look like this. Where you'd want the Unity workload (top left) to be installed - the rest are optional/unnecessary.
where would i find this?
project settings
open the Project Settings window (it's in the "Edit" menu in the menubar for me)
not to be confused with Preferences, which is for personal settings
ive just updated unity via the installer but i already have unity game dev enabled in modify
found it, what now?
After it's configured, you ought to get some red squiggly lines here if everything's working correctly
just have a look at the names -- those are the only valid inputs to GetAxis
so i would replace "GetAxisRaw" with Mouse X and Mouse Y?
Start would also be capitalized and the Visual Studio should not identify it as a miscellaneous file.
sorry, i honestly have no idea what im doing lmao
It's definitely not configured atm.
After you've added the Unity workload, you may need to reboot Unity.
How'd you guys learn coding?
Im just following a tutorial i know what this and that does but i have no idea how to write code on my own
Went to school
Oh im just learning this as a hobby to help my depression and its actually working and i love it
Can you recommend me to somewhere where i can learn?
To just learn C# on its own you could look at https://dotnet.microsoft.com/en-us/learn/csharp
I think it's a good idea to know C# decently before starting UNity (but it's not the only way to learn)
It will make it a lot easier though
Do i learn this on pc or can i do it on my phone?
PC is much better. You will be able to interactively learn
Alright
on the phone you'd just be passively watching videos
which is less likely to "stick"
Yep true
@ivory bobcat all the other errors are gone but im still getting this error
using System.Collections.Generic;
using UnityEngine;
public class PlayerCam
{
public float sensX;
public float sensY;
public Transform orientation;
float xRotation;
float yRotation;
private object transform;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
//get mouse input
float mouseX = Input.GetAxisRaw("X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
// rotate cam and orientation
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
Can somebody help me out? it says my input axis X is not setup?
urgent!
Pretty clear error
You don't have an axis called "X"
I think you probably want "Mouse X", which is a predefined one?
You can see your input axes in Project Settings -> Input Manager.,
Also just FYI it is an error for you to be using Time.deltaTime here. it's going to make your looking around very jittery
didn't I explain why "X" isn't a valid choice? :p
i didint comprehend
also, you still have private object transform; in there, and this still isn't a MonoBehaviour
because im special
So say that and ask for clarification
I did
where i crate a class???
Start with !learn to learn the baiscs
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
thanks!
you are currently trying to get a value for an input axis named "X". There is no such axis.
the Input Manager lists all valid axis names, such as "Horizontal" and "Vertical"
i am allowed to add screen record?
coding hurts my brain
if you have absolutely no idea what you're doing then you should stop whatever it is you're doing and follow the beginner pathways on Learn
this is the closest that i want my camera to act like, just can't figure out how to like fix it to not have this much move. Btw i did read what you send to me and i still can't understand what to do hahahaha
I'm talking to Christmas here, not you
i know i just wanted to tag you
You need to turn down the damping values
Higher values mean the camera moves and rotates more slowly
does anyone hav any idea y this isnt working?
Coroutines cannot delay other code
coroutines can only delay themselves
otherwise the entire game would freeze
You would have to put the next line inside the coroutine, and after the wait, if you want it to happen after the wait
ok
what do i need to do to fix my problem. Do i need to switch "X Axis" with MouseX?
thanks man it do look better now but it is still not what i would like it to be, i will try and figure it out on my own from now, sorry for bothering you
I said the problem is that you're trying to use this as an axis name:
"X"
You need to use a valid axis name, such as:
"Horizontal"
I don't know how to explain it and more clearly than that
ohhhhh
As mentioned several times, you need to use an axis name that exists. "X" is not one. "Mouse X" is one,
or the a and d in wasd, right?
yeah, I think you get both
I have this, works fine but for some reason on mobile its not smooth at all, I tried upping the animationDuration but it still wasnt smooth
private IEnumerator MovePanel(RectTransform panelRect, Vector3 startPos, Vector3 endPos)
{
float timeElapsed = 0f;
while (timeElapsed < animationDuration)
{
panelRect.anchoredPosition = Vector3.Lerp(startPos, endPos, timeElapsed / animationDuration);
timeElapsed += Time.deltaTime;
yield return null;
}
panelRect.anchoredPosition = endPos;
}
I only use the new input system, so I'm pretty fuzzy on theo ld input manaegr
SO instead of X i would put Horizontal?
haven't done a deep dive into either tbh
both are mapped
If you want mouse input, use "Mouse X"
How and here are you starting the coroutine?
I presume you mean where
StartCoroutine(MovePanel(rectTransform, rectTransform.anchoredPosition, openPosition));
On a button click
why arent these enums
unity would have to generate a source file based on your Input Manager settings
these aren't "hard-coded" into the engine
@wintry quarry
note that things like "the Q key" are enums -- see KeyCode
SO IN THEORY, this should work?
using System.Collections.Generic;
using UnityEngine;
public class PlayerCam: MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
float MouseXRotation;
float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
//get mouse input
float MouseX = Input.GetAxisRaw("X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Y") * Time.deltaTime * sensY;
yRotation += MouseX;
MouseXRotation -= mouseY;
MouseXRotation = Mathf.Clamp(MouseXRotation, -90f, 90f);
// rotate cam and orientation
transform.rotation = Quaternion.Euler(MouseXRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}
a
wrong msg reply
oh well
You are still using the wrong axis name here
It doesn't matter what you name those variables
fudge
You really need to stop and use !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
it doesn't seem like you understand very much about C# at all -- which is fine, you're new
but you need to have a better handle on what's going on here
you're right
I have this, works fine but for some reason on mobile its not smooth at all, I tried upping the animationDuration but it still wasnt smooth, i call it like this : StartCoroutine(MovePanel(rectTransform, rectTransform.anchoredPosition, openPosition));
on a button click
private IEnumerator MovePanel(RectTransform panelRect, Vector3 startPos, Vector3 endPos)
{
float timeElapsed = 0f;
while (timeElapsed < animationDuration)
{
panelRect.anchoredPosition = Vector3.Lerp(startPos, endPos, timeElapsed / animationDuration);
timeElapsed += Time.deltaTime;
yield return null;
}
panelRect.anchoredPosition = endPos;
}
helo
Why is it blurred out
I need to set it to other camera
for split screen
Please help about this man
anybodf7y
That field is only there to show you the currently-live camera
You aren't meant to mess with it
See here.
(and ask further questions in #🎥┃cinemachine !)
does anyone knows how to kill a specific tween if i set an id transform.DOScale(new Vector3(1.2f, 0.8f, 1.0f), moveDuration / 2).SetLoops(2, LoopType.Yoyo).SetId("StretchSqueeze");
DOTween.Kill("StretchSqueeze");
god I hate this doc you can't link specific sections
DOTween is the evolution of HOTween, a Unity Tween Engine
thanks just found it
I dont use it but does Dotween not return anything from the methods like StartCoroutine for example?
iirc it returns a Tween
so that should be stoppable, no?
yeah you can stop the Tween that way too
been a bit since I touched Dotween, been using another solution lately 😛
https://github.com/KyryloKuzyk/PrimeTween
@toxic cloak What's much easier (and less likely to .. be problematic if you have multiple items with the same tween string/int) is to just save a tween or sequence as a private member, and check if it's running when you need to kill/complete it
I have a pattern I use almost everywhere.. lemme dig it up and clean it up for ya
(and also just break if you have 2 components with the same id)
Seems a much more logical way to do it
Tween tween = transform.DOScale(...);
...
tween.Kill();
updated
Yes. Keep a reference -- much like with coroutines.
not necessarily - that just pauses it
sometimes you want to kill it (when the object is deleted) and sometimes you wanna complete it (because you have something important to do OnComplete)
sec i'm trying to find my original doc.. i literally just have a printout nearby because I use this pattern that often and always forget it 😛
private Sequence _revealTween;
private void OnDisable() => StopTweens();
private void StopTweens()
{
if (_revealTween?.IsActive() == true) _revealTween.Kill(); // or .Complete()
}
something like that
the primetween docs is also so much better
rhys mentioned to me last year that he was gonna do a different tweening library - is that his?
nope, i'm not familiar with this guys
not sure who that is lol
I'll have to check it out
yeah its pretty good, someone else here suggested last time.
He's been less active in this discord since his product is nearly market ready, but it's rhys_vdw (not gonna ping him). Guys a genius.
Thanks
I'm a bit too vested in the DOTween infrastructure.. i have a zillion (personal) utilities and libraries for it, so it's a bit much for me to change.. but I really would love to chat with 2020-Sharping to make a different decision
Like - why is there not a better "gravity" tween (instead of the weird-ish bounce tweens).. Or why isn't there any support for randomness in tweens.. or tween pooling.. etc
Or like, why do I need to either specify an ID or save a reference to kill/complete a tween instead of just letting the tween/sequence know when I create it what I want it to do when the GO dies/pauses/etc
lol, if in doubt roll your own
I'm too old to roll my own.. just barely smart enough to know that I'm not smart enough to do it
too old? to me?
I mean, I do appreciate that DG.DT has a pretty robust api surface, and for all intents and purposes it works, but i hate the docs
haha
"too old" at heart.
I've written one thing that I've OSS'd and I'm proud of, and it's so tiny and niche that I can't imagine applying the same effort to a full tweening library.. i'm happy to slap my own shitty extensions on someone else's work and gripe about it unfairly :p
man, youve had 4 years at least to write a tweening library, it takes literally weeks
You're right, I had nothing else to do in those 4 years :p
Of course, you could also write a wrapper for it
I gotta admit, the first time I needed a tweening library I looked at what was available and thought, wtf they are crap, so wrote my own
Here's a better example - sometimes I have what I call a "hit text" in my games - like numbers that float up in the UI from a position in the game.. but if the object underneath dies/disappears I want the hittext to continue to animate.. but if the LEVEL or something else ends, I want it to just delete instantly. Looks like this:
public class HitText : BetterMonoBehaviour
{
private Sequence _seq;
private bool _isTweenCompleteNormally = false;
public void ShowAndDestroy(string text, float duration, Color startColor, Color endColor)
{
Vector2 newPos = new(transform.localPosition.x + NumberUtils.Next(MinX, MaxX), transform.localPosition.y + NumberUtils.Next(MinY, MaxY)); // random end position, based on some min/max constraints
_seq = DOTween.Sequence();
_seq.Insert(0, transform.DOLocalMove(newPos, duration));
_seq.Insert(0, Text.DOColor(endColor, duration));
... more to it, but you get the idea ...
_seq.AppendCallback(() => _isTweenCompleteNormally = true);
_seq.OnComplete(() => Destroy(gameObject));
_seq.Play();
}
private void OnDisable()
{
if (!_isTweenCompleteNormally)
{
_seq?.Kill();
_isTweenCompleteNormally = false; // Set this to false so destroy doesn't try to destroy the GO again.
Destroy(gameObject);
}
}
}
this approach tracks the tween status directly with a bool (which gets "completed" at the end of the tween), and when the GO is disabled, if it's not complete, it just kills it
(normally "on complete" destroys it)
should this not be true?
_isTweenCompleteNormally = false; // Set this to false so destroy doesn't try to destroy the GO again.
other wise the enclosing if is still true
hm - been a while since I actually looked at this closely, but I think if I didn't have that flag then destroying it in OnDisable led to problems if the GO was destroyed elsehow
(that object was already destroyed or marked for destruction)
like Destroy() doesn't actually destroy it, but instead calls OnDisable and then Destroy
I seem to recall that I had a pretty hard lock without the flag
in this case, we want the hit text just destroyed/stopped if the parent GO is disabled but not destroyed, actually, despite what I said above
Transition from walk to idle and vice versa fires an extra time
guys when i buy an asset on unity asset store and try to open in unity editor the editor tell to read the EULA terms and agreed , i make this and when i try to do download the term message keep coming like a loop
how can i solve this?
I don't remember ever having to read and agree to an EULA in the editor for an asset store asset. Sounds like a problem with that particular asset
Reach out to the publisher
its not only this one every asset include the free ones having this issue
non-code question in a code chanel 🙄
No such thing happens for importing store assets
hey, I have a problem with this spray and the problem is that when I hit a wall, the car flies through the walls using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CarController : MonoBehaviour {
public float MoveSpeed = 50;
public float MaxSpeed = 15;
public float Drag = 0.98f;
public float SteerAngle = 20;
public float Traction = 1;
private Vector3 MoveForce;
void FixedUpdate() {
MoveForce += transform.forward * MoveSpeed * Input.GetAxis("Vertical") * Time.deltaTime;
transform.position += MoveForce * Time.deltaTime;
float steerInput = Input.GetAxis("Horizontal");
transform.Rotate(Vector3.up * steerInput * MoveForce.magnitude * SteerAngle * Time.deltaTime);
MoveForce *= Drag;
MoveForce = Vector3.ClampMagnitude(MoveForce, MaxSpeed);
Debug.DrawRay(transform.position, MoveForce.normalized * 3);
Debug.DrawRay(transform.position, transform.forward * 3, Color.blue);
MoveForce = Vector3.Lerp(MoveForce.normalized, transform.forward, Traction * Time.deltaTime) * MoveForce.magnitude;
}
}
Your issue is that you're moving with transform.position which teleport its to the next position rather than using physics.
You need to use a rigidbody and take the MoveForce and apply it as actual force to the rigidbody.
tehx
thx
but I have a stupid problem that I'm just starting with programming in C# and I don't really know how to do it
I know Microsoft has a C# course for you to learn C# solely https://dotnet.microsoft.com/en-us/learn/csharp
If you want to learn unitys API with C# you can do so via the pathways https://learn.unity.com/pathways
hey! just a general beginner question— why is VS more recommended than VScode for unity?
Anything wrong with using VScode? Or should I stick with VS? I always used VS without questioning why just because I was told it's the right one for unity but after stepping away from unity dev and trying out other projects I'm left wondering what's so different about the two
It has better Unity integration
More consistent and less fragile
P.s. a lot of people use Rider too
Hello! Did I miss something in my code ? I would like my "mobs" follow the character. But my code do really nothing x)
GameObject playerObj = GameObject.Find("Character");
for (var i = 0; i < mobs.Count; i++) {
float step = mobs[i].speed * Time.deltaTime;
mobs[i].UnityGameObject.transform.position = Vector2.MoveTowards(mobs[i].UnityGameObject.transform.position, playerObj.transform.position, step);
}
oooo I never heard of this one
Put logs
What function is this in
Rider is pretty solid.. it wasn't until recently that there was a free version you'd have to rely on early access versions... (also rider is pretty good at showing u optimizations in real-time)
the other ones can do this as well w/ AI plug-ins now-a-days
VSCode is my go-to IDE, for one I use certain plug-ins to code for embedded microprocessors.. And its lighter, and faster, and easier for me to jump around projects..
VSStudio is more of a full fledged IDE.. that VSCode can't directly replicate w/o the use of plugins. but nothing that can't be remedied
In the Update() ^^
So, as a beginner to both Unity and programming in general— VSStudio?
💯 thats where I started
- Don't use
Findin update. Find the character once, and keep using that reference. - Try logging
stepandmobs[i]to see if they're the values you expect (you might be referencing prefabs, or have accidentally set speed to 0) - check if the
mobsobjects have a component that conflicts with teleportation like CharacterControllers
you'll have the easiest transition into coding and unity w/
imo
as u progress then you'll have the know-how and ur own preferences on where to go from ther
First point done, ty!
First 3 logs from here
Where do you set mobs? Are they objects in the scene, or prefabs?
mobs is a simple List that I use to store objects from my own class called "Mob"
In the UnityGameObject I store the associated GameObject and in speed a simple float
I have this issue where all my prices aren't updating, value changes but text remains the same, can anyone help? https://paste.ofcode.org/a5q3yp5Nz8CsetNhy6vDJ2
set at 4.0f
should I maybe add a certain component to my prefab used to spawn mobs ?
atm my class is really empty no conflict possible I think ^^
List<Mob> mobs; // -> In the top of the class
And somewhere when I want to create the mobs I have:
GameObject scePrefab = Resources.Load<GameObject>("alien1_prefab");
Instantiate(scePrefab, new Vector2(prefabX,prefabY), Quaternion.identity);
mobs.Add( new Mob("name", scePrefab));
My mob spawn properly ^^
You shouldn't need Resources to spawn a prefab. Assign the prefab to a variable and use that variable in Instantiate . . .
Then I should in the Start function instantiate a reference to the prefab instead of use it each time ?
What script spawns the mobs? That script should have a reference to the mob prefab . . .
I created a script called "GameManager" which is used like an emulator to spawn enemies etc..
Also, this code passes the prefab to the Mob class, not the instantiated clone. You need to assign Instantiate to a variable and pass that variable instead . . .
That's fine, but I would use a script solely for managing and spawning the mob (MobManager) as a game manager encompasses managing game state and world values . . .
My current goal is not to do something perfect but just something working to learn a little bit Unity then yes I'm not focused on optimisation ^^
But thank you for your advices, I have changed some lines to optimize the thing (declaration on top..)
btw, my mobs is currently not moving x)
Logs are OK for me, the move code too I think ?
That's not an optimization. Typically, a script describes what it does and only pertains to one behaviour, hence, "mono" behaviour. I was trying to help steer you away from creating a monolithic GameManager class with everything inside of it . . .
Then is it better to create ScriptableObject?
They're not moving because you pass in a reference to the prefab (the object used to spawn into the scene) instead of the instantiated GameObject . . .
From my earlier response, you need to store the instantiated GameObject into a variable and pass that variable. Then you'll have the correct reference to the GameObject from the scene
Checkout Instantiate from the unity !docs. They have an example of this . . .
Ok thanks guys I'll look at this 🙂 !
public class EnemySpawner : MonoBehaviour
{
[SerializeField] private Enemy enemyPrefab;
private Enemy thisSpawnedEnemy;
void Start()
{
thisSpawnedEnemy = Instantiate(enemyPrefab, transform.position, Quaternion.identity);
thisSpawnedEnemy.DoEnemyStuff(); // this reference is not of the prefab.. but the Instantiated version of that prefab
}
}``` bare basic example
I finished the project 4 in Unity programming course!
are you going to make a small game based on what you learned?
thats the best way to put into practice and drill in the info
i'm always between that or continuing the course 😭
tbh just running through the course it might no "stick" as much you using what you learned so far for another mini-project
like trying to replicate from scratch what you did without following the page
funny thing is, doing a personal mini project IS part of this course 😅 which is why i'm always in doubt.
oh yeah then keep at it 💪
after each section, the course instructs to work on your own personal thing based on the design document you made..
It's where i struggle the most
yea cause thats where ideally you're not just copying info down, you're trying to force your brain to recount and rebuild that from memory / knowledge learned
I have horrid short term memory, its not so much a quick memorizing thing, maybe more of a "muscle" memory I think.
i feel you, my memory and attention spam are short, so i resorted to using Trello to note my thoughts and decide what the next course of action should be.
Very true; after watching a tutorial or learning smth from a blog, it's best to immediately redo the very thing you learned without looking at the resources
You will see how much you've retained and what you need to work on . . .
I have this, works fine but for some reason on mobile its not smooth at all, I tried upping the animationDuration but it still wasnt smooth, i call it like this : StartCoroutine(MovePanel(rectTransform, rectTransform.anchoredPosition, openPosition));
on a button click
private IEnumerator MovePanel(RectTransform panelRect, Vector3 startPos, Vector3 endPos)
{
float timeElapsed = 0f;
while (timeElapsed < animationDuration)
{
panelRect.anchoredPosition = Vector3.Lerp(startPos, endPos, timeElapsed / animationDuration);
timeElapsed += Time.deltaTime;
yield return null;
}
panelRect.anchoredPosition = endPos;
}
in what way is not smooth? maybe cause you're seeing your FPS capped
code itself looks fine
Could be, its like I can see it move bit by bit almost and doesnt give that smooth sliding in effect
go back to testing on your Editor. Put Application.targetFrameRate = 30 see if it looks the same
from the manual
- Android and iOS: Content is rendered at fixed 30 fps to conserve battery power, independent of the native refresh rate of the display.
How can i change the Texture of a Specific Face and get the Texture of a Specific Face of a MeshRenderer?
easier said than done. Iirc you need proper UV split and all that
Oh wow
does it have to be a specific face ? and why runtime
Im trying to make a Source based Lightning System (In source only the faces texture go either darker or brighter)
You want to make your own lighting system ?
this is more of a #archived-code-general or #archived-code-advanced and beyond my monkee brain comprehension
Oh okay
I don't understand what that means
Not sure where to put this, but I've been getting this error everytime I try to compile:
UnityEditor.dll assembly is referenced by user code, but this is not allowed. UnityEditor.BuildPlayerWindow:BuildPlayerAndRun ()
It is only when I include a library folder of plugins:
None of these plugins (to my knowledge) have any unity editor reference.
ClientCommon, AsyncData, GameServerCommon, are all my libraries with no unity references anywhere.
Is there anyway I can cause unity to give a stack trace on the build error, or more information than just "but this is not allowed"?
Hmm see if the !logs have any more info
Editor logs
@verbal dome```Fatal error in Unity CIL Linker
Mono.Linker.LinkerFatalErrorException: ILLink: error IL1010: Assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' cannot be loaded due to failure in processing 'ClientCommon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' reference
---> Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
at Unity.Linker.UnityAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
at Unity.IL2CPP.Common.AssemblyDependenciesComponent.CollectAssemblyDependencies(AssemblyDefinition assembly, Boolean throwOnUnresolved)
at Unity.IL2CPP.Common.AssemblyDependenciesComponent.GetReferencedAssembliesFor(AssemblyDefinition assembly)
at Unity.Linker.UnityLinkContext.ResolveReferences(AssemblyDefinition assembly)
at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
--- End of inner exception stack trace ---
at Mono.Linker.Steps.LoadReferencesStep.ProcessReferences(AssemblyDefinition assembly)
at Mono.Linker.Steps.BaseStep.Process(LinkContext context)
at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at Unity.Linker.UnityDriver.UnityRun(UnityLinkContext context, UnityPipeline p, LinkRequest linkerOptions, TinyProfiler2 tinyProfiler, ILogger customLogger)
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(TinyProfiler2 tinyProfiler, ILogger customLogger)
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling()
at Unity.Linker.UnityDriver.RunDriver()
*** Tundra build failed (0.33 seconds), 1 items updated, 49 evaluated
UnityEditor.dll assembly is referenced by user code, but this is not allowed.```
Thank you. didn't know of the logs. I've discovered the problem.
What was it?
I have client and server code in the same unity project; the client code has the "ClientCommon", and so does the server. These are seperate library folders. I seem to have forgotten to provide the necessary dependencies to the Client lib folder to handle it's library.
The struggle was not having a stack trace.
Thank you so much.
Np👍 Logs often have the info that is missing from errors
Was it related to newtonsoft here?
Yes, it requires that dependency.
Hey everyone, quick question. I have a Task running during an event in my game. when the user presses pause, the games timescale is set to 0. everything is the game pauses except on a very very rare occasion this method seems to run infinitly fast..
the method im about to share is supposed to spawn enemies every (x) amount of time.. but when i pause, the enemies will eradically spawn (RARE).
public async Task StartSpawning(RallyPoint activeRally)
{
if (activeRally.spawnsPerMin == 0)
{
Debug.LogError($"spawnsPerMin is set to 0 : {activeRally}");
return;
}
currentRally = activeRally;
isRallyActive = true;
float elapsedTime = 0f;
float spawnInterval = 0f;
float rallyDuration = activeRally.totalRallyDuration;
float spawnrRateMultiplierActivated = 1f;
float rate = 60f / activeRally.spawnsPerMin;
float critialMomentSpawnIntesity = 1 - (currentRally.critialMomentSpawnIntesity / 2f);
float criticalPoint = rallyDuration * currentRally.critialMomentStartTime;
while (isRallyActive)
{
elapsedTime += Time.deltaTime;
elapsedTime = Mathf.Clamp(elapsedTime, 0f, rallyDuration);
if (rallyDuration - elapsedTime <= criticalPoint) spawnrRateMultiplierActivated = critialMomentSpawnIntesity;
rallyManager.rallyTimer.SetTimer(rallyDuration - elapsedTime);
currentRally.TimerTextInitialize();
if (elapsedTime >= rallyDuration)
{
currentRally.Completed();
EndRally();
return;
}
if (!isRallyActive)
{
return;
}
if (spawnInterval == 0f)
{
SpawnEnemyGroup();
}
spawnInterval += Time.deltaTime;
spawnInterval = Mathf.Clamp(spawnInterval, 0f, rate * spawnrRateMultiplierActivated);
if (spawnInterval >= rate * spawnrRateMultiplierActivated) spawnInterval = 0f;
await Task.Yield();
}
}```
maybe try waiting to execute pause code at the end of the frame? could that have an impact
deltaTime is affected when your game is paused. try using unscaledDeltaTime instead . . .
hmm ok interesting, i'll look into it.
no i need the game to pause, that's not the issue
oh, so you don't want this to continue running?
it’s incorrectly pausing i think
so you're saying that enemies will occasionally spawn way too fast?
if you look closely at my post you'll notice that i DO want time to be affected by the pause. the issue is that it rarely does continue for no reason i can figure out
are you sure that SpawnEnemyGroup isn't malfunctioning?
exactly, but while the game is paused only
you can throw some log statements in there to find out how many times your code is running
so,, the issue is that it is so rare, i don't know how to debug it, i could be playtesting for hours just to get it to happen once...
would try this then because it sounds like something thats only happening sometimes when other parts of the code takes too long
How do you know the issue lies in this code at all?
i'm genuilnly curious, how could that function me malfunctioning? it's not effected by anything.. it has to do with the while loop im almost certain
well, I can't see the code
it could be anything
it could be a method that says if (Time.deltaTime == 0) { SpawnThreeTrillionSpiders(); }
{
int enemyIndex = GetRandomEnemyIndex();
Vector3 pos = Vector3.zero;
float randomAngle = Random.Range(0, 360);
for (int i = 0; i < currentRally.amountPerSpawn; i++)
{
if (inactivePools[enemyIndex].Count == 0 || activePool.Count >= activeEnemyLimit) continue;
Enemy enemy = inactivePools[enemyIndex][0];
enemy.player = player;
enemy.data = enemyTypesArray[enemyIndex];
inactivePools[enemyIndex].Remove(enemy);
if (activePool.Contains(enemy)) activePool.Remove(enemy);
activePool.Add(enemy);
enemy.transform.position = player.transform.position + Vector3.up;
enemy.transform.RotateAround(player.transform.position, Vector3.forward, randomAngle);
enemy.transform.Rotate(new Vector3(0f, 0f, -randomAngle));
if (pos == Vector3.zero)
{
Vector3 direction = (enemy.transform.position - player.transform.position).normalized;
pos = player.transform.position + direction * currentRally.spawnDistance;
}
Vector3 newPos = pos + Random.onUnitSphere;
newPos.z = 0f;
enemy.transform.position = newPos;
particleManager.CreateSpawnEffect(newPos);
if (i == 0)
{
soundManager.PlayClip(enemySpawn, newPos, 1);
}
enemy.gameObject.SetActive(true);
}
int GetRandomEnemyIndex()
{
int enemyIndex = Mathf.FloorToInt(Random.Range(0f, enemyTypesArray.Length));
if (inactivePools[enemyIndex].Count != 0 || enemyTypesArray.Length == 1) return enemyIndex;
else
{
for (int i = 0; i < 10; i++)
{
int newIndex = Mathf.FloorToInt(Random.Range(0f, enemyTypesArray.Length));
if (inactivePools[newIndex].Count != 0)
{
enemyIndex = newIndex;
return enemyIndex;
}
}
}
return enemyIndex;
}
}```
hahahah
that seems fine; there's no time dependency in there
I would add a bunch of logging so that when the issue does happen again, you'll have more information
I don't actually know what happens when you await Task.Yield();. I've only done a little bit with async methods in a Unity context (and most of that has been involving Awaitable
when i add alot of logs in while loop my comp slows down so much
Do you get a very large number of spawns in one frame?
From my understanding it always waits for at least one frame, sometimes more.
Need to investigate further though..
if you think it's pause-related, I'd suggest writing code to pause and unpause the game very rapidly. that might help to trigger the bug more often
from what i know, im pretty sure await Task.Yield(); allows the while loop to perform on the next frame kinda
is there a reason you aren't just using a coroutine?
I'm much more familiar with that behavior
i was about to say
I thought about doing this as a last resort. see if you guys had a better idea than me
Most people use coroutines in this type of situations, yeah.
Only reason I really use async is for stuff that needs to run in the editor too (I know EditorCoroutines exists but what if I want them to also work in playmode)
yes there is a very big reason why i'm not using coroutine. and the quick answer is becasue coroutines don't allow the 'flexibility' i need to run my opperations. i have alot of Tasks waiting for other ones to complete and a few other reasons.
i don't think Task is affected by the timeScale, or unity related Time. maybe that's why it acts up randomly and runs . . .
i mean at the end of the day why not just hard code in that the code doesnt execute at 0 timescale
no it is. becasue every other task i have running will pause when the user pauses. this is the only task* with a bug
I wouldn't expect it to have any bearing
yeah, i've never messed with Task before, so this is uncharted territory . . .
Awaitable is their own version of using Task, right?
It's an alternative, yes
so here is what i'm thinking... I think when the game pauses specifically when the spawnenemygroup is suppoed to run, the while loop continues with the same elapsedtime -> resulting in running the same condition over and over again
You are correct in that Task.Yield isnt affected by time/time scale. It just waits until the next time it gets a chance to check
I've used it for a game before. The game actions are implemented as Awaitable-returning methods. If I'm just simulating game logic, I skip all of the visual effects and the methods basically run synchronously. If I'm displaying an action, I run effects and await the completion of each step
Which is usually the next frame
I have to wonder if it's not always the next frame 😉
All you're doing is throwing your task back into a queue
ya, so should i have a check before spawning to check if the game is paused? (seems like a temporary fix)
place a check within the top of the loop for timeScale being 0 and yield; that should stop it from running . . .
i guess i'll just do that just to see if i ever see the issue again...
I'd suggest adding a check that you aren't spawning twice in the same frame
log a warning if it happens
that'll help you spot the issue if it manages to happen again
idk what you mean can you write a line of code expressing what you mean?
Using Task.Yield() lke that is very alien to me
presumably just if (Time.timeScale == 0) { Task.Yield(); }
of course, if it's instantly resuming the task, then you'll spin forever (:
I don't know how it behaves
just check if timeScale is 0 (basically, when the game is paused). if so, yield . . .
I would suggest using Awaitable, which lets you explicitly wait for the next frame
but waiting for the next from doesnt make any sense becasue when the game pauses, the frames continue... so that wouldn't fix it?
so what?
the timescale is zero
that'll stop it from running if the SpawnEnemyGroup methosd is called and uses deltaTime when it still has a value . . .
so, that means how every many frames i'm paused i will expect the enemy spawner to spawn that many times...
You'd wantwhile , not if, right
oh, I see how the bug is happening
yeah, I get it
if (spawnInterval == 0f)
{
SpawnEnemyGroup();
}
spawnInterval += Time.deltaTime;
spawnInterval = Mathf.Clamp(spawnInterval, 0f, rate * spawnrRateMultiplierActivated);
if (spawnInterval >= rate * spawnrRateMultiplierActivated) spawnInterval = 0f;
You spawn a group if spawnInterval is zero
You set it to zero if the value gets too large
If you pause RIGHT as it gets past this limit, it'll have a spawnInterval of zero every frame
exactly
This is just a bug in your code. It's written wrongly.
You should do something more like this
so a quick fix is to have a check right there to see if the game is paused
delay -= Time.deltaTime;
while (delay <= 0) {
delay += interval;
DoThing();
}
interval is how long to go between spawns
delay is how long until the next spawn happens
using while makes sure it works right even if the interval is so fast that you get more than one spawn per frame
(and, obviously, you'll want to spawn enemies in that loop, too)
There is nothing conceptually wrong with a zero-duration frame. Any time-dependent processes shouldn't proceed at all during it
(Also, the way you wrote this will cause slight errors over time -- notice how you just set spawnInterval to zero, no matter how far you overshot the target)
im aware of this, this code of mine is old. i will subract it
so, just rewrite it so that it spawns enemies in response to you going past the limit
instead of setting the counter to 0 and then reacting one frame later
so for this, i'm not sure i understand its logic?
suppose you want to spawn 1000 enemies per second
you are running the game at 10 frames per second
delay -= 0.1 -> suppose delay is now -0.007
interval is 0.001. we add interval to delay until it becomes a positive number again
spawning eight enemies in the process
(i added an extra line to the example to call a method)
why do you want to do this part?
to handle this situation
It is not strictly necessary, but it's more correct.
It's more relevant for things like fast-firing weapons
wouldn't this not solve the issue, becasue what if the pause happens when the delay reaches the correct value? same issue happens again
it's completely fine
notice how deltaTime isn't used anywhere inside the loop
we are simply adding interval to delay until the delay value becomes positive
Your code does something entirely different. It checks if spawnInterval is too big and sets it to zero if that happens
which means that it can get parked at zero forever if you pause at the exactly correct frame
Your spawn condition has nothing to do with checking if too much time has passed. It only checks if spawnInterval is zero.
It does become zero if you just passed the threshold...but it also becomes zero if the game is paused at the wrong moment
ok so i think i get it now.. correct me if i'm still wrong lol
- the game reaches the spawnenemygroup().
- then enters a new while loop for the delay.
- the interval is fixed and is used to reach the delay amount.
- once delay is reached, execute SpawnEnemyGroup()
correct?
No. Each time the loop runs, we spawn a group.
No, that wouldn't have done anything
oh smh
how do i pause at the end of fram?
well, with Awaitable, you can ask to resume at the end of the frame
but that's non-relevant here
ok
the core problem would remain: spawnInterval is stuck at zero forever
- Subtract
Time.deltaTimefrom the delay every frame - As long as the delay is <= 0:
- Add the interval to the delay
- Spawn enemies
That's it
I mean, sure, but I'd rather just write code that doesn't break when the timescale is zero
There's a fundamental correctness problem with the existing code
i'm sorry, i'm just not understanding how this works. the logical side of it.. i must be missing something, in my mind, what you are doing is just pushing back the inevitable sort of say... Time.deltatime is affected my timescale... so i don;t see how this helps during the paus
Let's say the timescale is zero
Time.deltaTime is zero.
delay is currently 0.01
yes
Does anything happen?
no becasue deltatime is 0
Right. delay -= Time.deltaTime does nothing
and delay <= 0 is false, so the loop doesn't run
Now suppose delay is -0.01
What happens?
i don;t want the condition to fail. that would complete the while loop
teh task would end
This would be useless if it wasn't stuck inside something that looped. It'd run once and bail out.
nothing agian to answer your question
Incorrect.
while (delay <= 0) {
delay += interval;
SpawnThing();
}
This condition is now true.
We add interval to delay and call SpawnThing();
If interval is large enough, the loop terminates.
Otherwise, the loop runs again.
i don't want to spawn thing lol
i don;t want to do anything ! lol
What?
thats the whole point
I don't think you're understanding anything I'm saying
i must not be lol
I am showing you how this approach correctly handles a timescale of zero
when the game is paused. i want to do nothing and wait until unpaused
notably, delay can't wind up being non-positive during a frame with a deltaTime of zero, because we subtract from it before we check it
your code subtracts from it one frame before it checks the value
you have to write the code, becasue i'm getting mixed up withe the english and code intermixing. just take a small part of my function and write in your method of success so i can read the code
This is it.
Replace interval with how frequently enemies should spawn per second
hold on a sec. i'm going to give you a block. and edit it so it's correct..
That's how the bug happened in the first place. It set spawnInterval to zero on the very last non-paused frame (but didn't do anything immediately).
One frame later, it started spamming enemies, because spawnInterval was parked at zero and never changed from that point
delay is like the bird in flappy bird, falling lower and lower
When you fall too low, you tap it until you are high enough
The approach I suggested doesn't do that -- but even if you did write it in a way that can cause the enemies to spawn late, it won't malfunction (beyond being one frame off)
{
elapsedTime += Time.deltaTime;
elapsedTime = Mathf.Clamp(elapsedTime, 0f, rallyDuration);
if (elapsedTime >= rallyDuration)
{
currentRally.Completed();
EndRally();
return;
}
if (spawnInterval == 0f) SpawnEnemyGroup();
spawnInterval += Time.deltaTime;
if (spawnInterval >= rate * spawnrRateMultiplierActivated) spawnInterval = 0f;
await Task.Yield();
}```
add what you are saying to this to make it work
i made the while(true) for you
while (isRallyActive)
{
elapsedTime += Time.deltaTime;
elapsedTime = Mathf.Clamp(elapsedTime, 0f, rallyDuration);
if (elapsedTime >= rallyDuration)
{
currentRally.Completed();
EndRally();
return;
}
float interval = rate * spawnrRateMultiplierActivated;
delay -= Time.deltaTime;
while (delay <= 0) {
delay += interval;
SpawnEnemyGroup();
}
await Task.Yield();
}
something along these lines.
note that I have renamed spawnInterval to delay (because that's what it represesnts now
the name was already misleading, though: it's not the spawning interval
spawnTimer could be more appropriate
You may want a sanity check that interval is not zero
This kills the game
so how do i reset the delay? or when?
delay += interval;
this is inside of the while loop.
ok so when the game is unpaused.. the delay is always greater than 0.. correct?
At the end of the frame, delay will always be greater than zero
No matter what
If it isn't greater than zero, the while loop will add to it until it's greater than zero
This is a nice invariant. We know that, on the next frame, delay <= 0 must be false (before we subtract Time.deltaTime, at least)
On a paused frame, Time.deltaTime is zero
So we are also guaranteed that delay <= 0 will still be false
and thus nothing can possibly spawn on a pause frame
ok wait .. hold on, i'm not understanding how delay is just floating around with no regulation... can delay get way too big?
Why would it? We only add to it until it's greater than zero
then we stop
We are very carefully regulating the value of delay, to the contrary..
r yall still on this..
omg my mind is just not comprehending this... shit
lol its just funny cause i thought it was a 2 line change
lol to unscaled? lmao
Do an example by hand, then. Pick an interval value (maybe 0.1) and a deltaTime value (maybe 0.03, or maybe 0.3)
See what happens.
i trust you that it will work... i just don't use code that i don;t understand.. while i have you here (and i'm very appreciative of it) i'd love to understand it. (even though you have explained it probably well, it's just not clicking for me) sadly...
That is why I suggested you work an example by hand.
Seeing how it behaves with:
- intervals much longer than the frame time
- intervals much shorter than the frame time
will illustrate why it's correct
no longer can't move the object in the scene, why is that happening?
Show your entire editor window in #💻┃unity-talk (this isn't a code problem)
and no they are not static
oh sorry
i will take this into the areana with me and start writing it by hand, hopfully it will make sense after i do that. lol thank you
What are you trying to move? You seem to have 2 objects selected
the witch
I wonder if having a deactivated object selected is at all relevant
Or is that just hovered on
oh, that's just hovered
before i go, does it matter what i set the delay to? or is that just prefference
How are you moving it?
Start at interval if you want the spawner to wait for one cycle before spawning an enemy
from the transform component
Start at zero if it should instantly spawn
And do the values in the component change?
yes
Then it moves.
oh wait... doesnt this code spawn the enemy (interval) amoutn of times ?
Maybe a video would be more helpful to see what you mean
No. It spawns an enemy every interval seconds.
what ever it called
those are handles
yes it doesn't show them
oh, one thing
switch from "Center" to "Pivot" (the shortcut is Z)
I bet the handles are just way off the screen
sorry, awful crop
top left of the scene view
Center finds the center of all of the bounding boxes of the renderers and colliders on the object
which can be very far away from the actual pivot point
I've seen 3 instances of someone getting pranked by Center today
I love you already
what ever this creature is, I'm a fan of it from now on
thank you so much
i get pranked by it every few days
it's very tricky because whenever you create a new project, your UI layouts and most general preferences get reset
same with pivot/center
quite annoying imo
i have a room object with this script on it
[SerializeField] private Animator anim;
[SerializeField] private BoxCollider boxCol;
public bool doorLocked = false;
private void OnTriggerStay(Collider other)
{
if (other.gameObject.CompareTag("Player") && doorLocked == false)
{
OpenDoorServerRpc();
}
}
[ServerRpc(RequireOwnership = false)]
private void OpenDoorServerRpc()
{
Debug.Log("ClientRPC received. Playing door animation...");
if (anim != null)
{
anim.Play("Door Open");
}
else
{
Debug.LogError("Animator component is missing!");
}
}
the boxCol component is the collider of the door which is a child object of the room
and i want to detect collision coming from the boxCol component and check if the collision touching the boxCol component is comparetag player and do something if it is
can someone please help how to do that
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Anyone know how to correctly play sound for hitting and then destroying an object? Im currently using the same script for different objects and they are each having their specific data set in the inspector for them. I also have a SoundManager empty game object with 2 AudioSources. Just cant figure out how to get one sound and the other into the inspector slots.
You can do PlayOneShot on the audio source instead of assigning a clip to it. Check the API docs of the audio source.
wouldn't that mean i have to use the same breaking and destroying sound for all the objects that have the script if i set it within the script?
No. You can pass in whatever sound you want.
You can get the clip reference from the destroyed object for example.
destroySFX.Play(thisObjectSound)
Not play, but you get the point I hope
what would thisObjectSound be?
so i'd get rid of the empty game object with the sources on it to play the sound?
An Audi clip
No, you can do it with it as well. I was just basing off the code that you shared.
soundManager.Play(sound)
And the sound manager would call the play one shot or something on the audio source.
im confused though
how do i get the audio sources into the inspector?
cause when i try dragging them in it only puts the top audio source into the audio source reference i have
Where are you dragging the audio sources from and to where(a prefab? An object in the scene?)
im trying to drag the top audio source from this SoundManager to the top reference slot and the bottom audio source to the bottom reference slot.
but it only lets me use the top audio source from the SoundManager object in the reference when i drag it in
I want it to play the footstepsfx on getting damaged and dashsfx on getting destroyed
but i dont wanna just hardcode those sounds into the script because i wanna make another object eventually that will have a different sound when getting hit and destroyed so i can just change it in the inspector
If you have a setup like this, it might be wiser to only reference the sound manager object in your destructible object and just call the appropriate methods on it. Referencing the audio sources directly beats the purpose of a sound manager.
ooh ok, ya i just tried it like this cause i saw a post online with someone talking about good ways to do it and that was one of them
is there a better setup i should be using to play the different audio sounds for each object?
if i do it like that though wouldnt i still need to have something referenced in the inspector though so the sounds can be different per object?
Yes, you'll need to reference the audio clips of the different sounds you want to play. That's it.
Then you probably misunderstood them. Because what you're doing now is the most(or almost) inefficient way.
if im just referencing audioclips instead of audiosources how would i modify the pitch and volume settings for each individual object?
You can have this data defined on the destroyable object as well and pass it all together to the sound manager that would actual deal with it.
Ideally, you'd use scriptable objects here so that the sound data is encapsulated in a separate object and doesn't clutter the destroyable object inspector.
i was trying a bit to figure out how to use scriptable objects, but i couldn't really find/figure anything out that could help with using it in the use case of a resource gathering system
Let's say that I have empty GameObjectAbc and a MonoBehaviour ScriptAbc.cs for it.
Can I add GameObejcts and Componenets from that script to compose a tree where GameObjectAbc is a root?
If yes then how is this possible to add a GameObject as a child to the ScriptAbc component? I've read that components can't have GameObjects as parents.
In other words: I want to create a scene tree purely from the code
i tried watching a few vids too talking about the basics of it, but none of what they were showing seemed to be close to what I'm trying to use scriptable objects for
It was all just like making a basic scriptableobject asset from the asset menu and then setting simple values in that but not actually using them for anything in the game
basically i dont rlly understand how to convert my current script with all the methods and variables within into a scriptable object system
the way I do it is
Item.cs - describes an item. does not change at runtime
public class Item : ScriptableObject {
string name;
//Add anything you need here
}
Inventory.cs, assigned to each player
Dictionary<Item, int> items; //contains number of items
but if you need to store the state of an item there's other ways to do it
seems to align with what you're doing
You use scriptable objects to define many different data sets. Then you use the one so that had the desired data set. You can pass it around for example, instead of passing tens of separate variables.
im more trying to do like rocks and trees and ores that spawn around my map that i can mine and all have different stats without having to make a new script and prefab for each type
Those aren't inventory items, you can simply make a HarvestableResource script. When the object is hit, make it drop an item
You only need one HarvestableResource, no need to derive it. Then set the dropped item to the item of your choice like rock or wood
if i use scriptable objects and i cant change them at runtime would that make it not possible to have like a weapon scriptable object that has an int for damage and have that value be like 10 and then be able to change that damage value of the item to like 20 if something happens in game
just curious why do you want to use a scriptable object for this? do you intend to create 1 scriptable object per tree/rock?
uh idk, im still pretty new, that's just what i got recommended to use
It depends on the context. At the moment I recommend to use scriptable objects for sound data, as apparently they want different sounds with different pitches and what not for different object types.
Then you could just pass the SO reference to your sound manager and it would play the desired sound with your settings.
Think of the workflow of prefab vs scriptable object
If you use a prefab, you can simply Instantiate destructible trees and rocks
For scriptable objects, you'll have to make a copy of the scriptable object, and represent that ScriptableObject in the world(through a tree/rock object)
I'm not saying avoid SOs entirely but think about why you need them
This is what i currently have right now, one script called ResourceNode on each object that i want to be its own thing like iron ore or gold ore and they have their own values set in the inspector for the script. And another script called Playerhit which is just like a temporary script i have to test the functions before i add my tool system. https://paste.ofcode.org/38wJnL6n2yU3rLnUvVFXHgh https://paste.ofcode.org/32h48wervqkLFVCtcswFgwF
That doesn't make sense. Components don't know anything about the hierarchy. They're just attached to a GameObject. gameObjects take care of hierarchy and contain one or many components. That's the only relationship there is.
thanks, that's what I wanted to hear, now I'm sure
I'm learning with chatgpt and it tried to add GameObject as a child to the component and I freaked out
gpt is trash not a good way to learn
chatgpt has never coded a game before in unity don't let it tell you what to do
everything it spits out is garbled hearsay
it's good, I was able to do advanced things in godot much faster in compare to manual research
it's even worse for godot
it was even worse in godot but I was able to recreate his intentions
if its good why are you here lol
it's not perfect
because 3.x and 4.x API changed a lot, using Godot for 4.x can give very wrong answers
I would spam you out with questions if not AI
we rather get questions to clairfy something than you going to GPT and learning worse
oh no, I'm not learning from it... I'm gathering info and learning from that
not even about being perfect, is just bad. period.
you wont learn anything, and whatever you learn is probably flimsy at best
LMAO if I trusted this AI I wouldn't achieve anything