#💻┃code-beginner
1 messages · Page 836 of 1
i dont wanna be a programmer but i have to do this pathway to enroll on to an artist scholarship(mindblowing)
then read ur errors correctly ?
i came here to find out how...
if they require you to know that I think you'll need it during it as well no?
👁️ 👁️
so why not start with basic c#
youd think so lmao
learning the basics doesn't need to make you a programmer.. at least you can then read code
agreed
okay fresh start lmao... apologies for coming in hot
by configure my ide i assume like using extensions and that right?
you only need Unity extension, its all outlined in the link sent
if you did those steps and still have issues, check here as well
https://unity.huh.how/ide-configuration/visual-studio-code#if-you-are-experiencing-issues
If your IDE isn't providing autocomplete suggestions or underlining errors in red, then it needs to be configured.
This
i don't really have more info, i'm not familiar enough to prescribe anything
okay so the error is line 2 but thats not something iv written, that existed from the moment i created the script
also i did the configuration guide ty
If only there was some way to remove it
will it not break anything? since it was there from creation
it wasn't there when you created the script
pretty sure that's not true, that's not part of unity's templates.
they were probably added by mistake from an auto-import. (which wouldve been triggered by you)
you should configure your ide, then it will be easier to see that stuff can/should be removed
i did the guide so ill remove it and hoipefully that'll sort it
you should configure your ide.
funny how VSC underlines Behaviour as a spelling error 😆
because it is smh 
i just did it following the link provided
it hasn't been configured
you should see MonoBehaviour, UnityEngine, GameObject, and Collider in green, and Destroy, Instantiate, and Rotate in yellow
they aren't highlighted properly, a sign that it hasn't been configured
have you installed the .net sdk via the .net install tool in vscode? (in vscode, command palette (ctrl+shift+p) > install .net sdk)
(once you've installed that you would restart vscode)
if it were configured a very obvious thing would be it would underline in red the line that is erroring in unity
guyz the square is not coming upto the background i checked order in layer but still not showing...
sprite renderer and canvas items dont match at all . (assuming the square is also sprite renderer since you haven't shown it)
they are not compatible
also not a coding question
Hey, guys! I didn't know the DDOL can be used to save actually values and preferences like we do with PlayerPrefs, JSON etc
Is it an efficient way to actually save values this way with DDOL?
DDOL has nothing to do with saving values..
Or it works only when changing scenes
So I think it wont actually store values in memory
they will gone after restarting the game
DDOL does not save values. DDOL is only to prevent an object from being destroyed when the scene is unloaded
technically JSON is just a way to format text its not a save method in itself, what you probably mean is saving through a File like IO operations
so it will save values only across scenes its not effective on anything else
you can save a JSON formatted text into PlayerPrefs 🤯
using a DDOL to store values only lasts as long as the current session cause its all in memory
as i mentioned
again json is just format.. is not a save method
There isn't anything else
you mean a File on your PC ?
theres many ways, those are two common ones though
I want to try and save values using this method but right now I have to go off so probably tomorrow I will be around.
the common way is
Json format into a file saved in Application.persistentDataPath
playerprefs for more "temporary" options (maybe muting a session when it starts, video settings etc.)
playerprefs should ideally never be used for gameplay save data and should just be used for preferences for the player application hence the name PlayerPrefs
it should especially never be used for gameplay on Windows because they get saved to the windows registry
I use it for session cookies when user logs in and stores their tooken
Whats a ddol
DontDestroyOnLoad
Guys where do I show my games
Ty
Hello <@&502884371011731486> where can I report a scammer?
@upper tendon with screenshots/IDs
How to attach text to a gameobject?
A floating text in front of it
If it's text alone, you can use the TextMeshPro component (not the UGUI one) which you can space anywhere you wish. If you need more UI stuff, you can use World Space Canvas/UI Toolkit Document
Hello yall, is this where I can ask for some help?
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
I'm having a bit of an issue here in Unity where I'm experincing quite a bit of frame skips. I don't really know what I'm doing since I'm a turbo beginner, so if anybody has any idea what I could do to fix this, I'd appreciate any help.
Looks to be related to your camera logic more than anything
Share the code here
!code
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 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.
the camera code?
Yes
//using UnityEngine;
public class CameraLook : MonoBehaviour
{
public float mouseSensitivity = 100f;
private float xRotation = 0f;
private Transform playerBody;
void Start()
{
playerBody = transform.parent;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}
you are a SAINT
Can someone help me take a look at my code and help me figure out why my SoundControl() method (the one at the very bottom) isn't fully working?
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 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.
sorry more used to mobile so accidentally hit enter and sent early
wasnt done typing
https://paste.ofcode.org/wvd8SyGyvtEEUxcGj7Ntb3 Can someone help me take a look at my code and help me figure out why my SoundControl() method (the one at the very bottom) isn't fully working? The jump sound effect is working but the walk run and crouch audio doesnt activate. for the record. For the record the debug output is coming out 1 if not moving, 7 if crouching and moving, and 8 when walking and sprinting
are you supposed to be able to walk-crouch/sprint-crouch/air-crouch?
like why is it a separate boolean instead of a separate state
Followed two separate tutorials from the same guy. That's how he did it and I didn't know enough to really question it at the time
right but how do you want your game to behave now
Yes crouching is supposed to be allowed to happen when walking/running/in air
you'll probably want to separate what happens when doing those on their own vs doing those whilst crouching then
or do you want it to play both the crouching sound at the same time as walking/sprinting
also seems like you'd be restarting the audiosource every frame?
I'll try separating some things then
https://paste.ofcode.org/9kyL5M8XdWSvwmrqKmXEYi Updated the code a bit but not sure if this is the right direction or not, the walking and crouching audio will actually play now but for some reason it will only play if you sprint first and it will immediately stop if you do any other movement
@naive pawn Just wanted to say thanks again for the help yesterday. Got my culling system working and it's really efficient. 🙂
No need for help anymore I managed to kickflip myself into a solution
Guyz can anyone help me related the Github,
if we pushed the assets project settings already and we want to push more small files then should we require to send whle asset file again...?
when you upload stuff to github, it's the changes
this should be kinda obvious when you're staging the new changes
automatically fetches changes in that file which we uploaded alredy...
or we have to push the changes separeatly?
Nothing is being pushed automatically. You have full control of what is being staged, committed and pushed.
How(what client) are you using git?
Hello everyone this might be a stupid question but how do i learn code and then how to use code in games? (c#)
Search io internet there are tonsof tutorials...
and for using/applying code you will need external coder like visual studio code is good at all...
there are c# resources pinned in this channel
Everyone is saying that starting practically is the best way but i dont know how to start and with what
most important is just to start tbh
try making small games
alright
dont ry big projects early u can make flappy bird clone
also if u stuck at any place u can take help of AI or this server anytime
sounds good
don't use AI while learning, you don't have the necessary experience to actually utilize it properly and you will end up shooting yourself in the foot
Im having an issue with this script that the drag(lineardamping) does not work and and speed control text is causing my movement to break if i remove it. Im following this tutorial 
https://www.youtube.com/watch?v=f473C43s8nE
Guys im getting this error: Can't add script behaviour 'FliegeAnimation'. The script needs to derive from MonoBehaviour!
FliegeAnimation means flying animation its german
@frigid barn idk why but i cant awnser your Dm
!code
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 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.
no need to delegate to DMs, it negates the benefits of having a community server to begin with
does it derive from monobehaviour?
like this?
i think so
do you mean this? : public class FliegeAnimation : MonoBehaviour
check in unity console if there aren't any showing up in your ide, you may need to configure it
ill try
im using visual studio and there was some mistakes and copilot fixed it for me i think and now its saying no problems found but the same issue pops up
never mind i fixed it
the paste expired
Looks like paste site expired
Hello everyone
can I somehow break out of if statement?
by avoiding needing to 😄
whats the usecase
if (Physics.Raycast(start_trans.position, start_trans.forward, out RaycastHit hit, Mathf.Infinity, check_mask))
{
assumed_target = hit.transform.GetComponentInParent<AggressionTarget>();
if(cached.Contains(assumed_target))... ugh skip no next condition?
}
else if (Physics.SphereCast(start_trans.position, spherecast_radius, start_trans.forward, out hit, Mathf.Infinity, check_mask))
{
assumed_target = hit.transform.GetComponentInParent<AggressionTarget>();
}
else
{
assumed_target = Accountant.instance.RequestTargetHomingClosestBlacklist(PlayerAsTarget.instance, start_trans.position, start_trans.forward, coeff, cut_coeff, cached);
}
I figured I need to exclude repeats
...I guess I need a small method
bool one
... ugh skip no next condition?
where do you want control flow to go exactly?
Physics.Raycast(start_trans.position, start_trans.forward, out RaycastHit hit, Mathf.Infinity, check_mask))
{
assumed_target = hit.transform.GetComponentInParent<AggressionTarget>();
if(cached.Contains(assumed_target))... ugh skip no next condition?
Pull all of this stuff out of the if structure
it already skips the "next" condition because you're already in the if
it's almost like a language is designed to prevent me from building huge ugly chunks of poorly readable code
save the raycast results to variable(s), do all the processing you need, then start the branches
to spherecast from raycast and then if it fails to generic request
so you want it to check the next condition, not skip?
I want to skip this one and check next one
not sure if this wording makes sense on second thought
but you got it
and you have more stuff after that if (cached...?
no
then what's the point of this being a separate condition
this is just a chain of or's and and's
there really is none
no wait
no abort waiting there is no point of not putting it at check
but like
seems like I either have to make a small method
or I dunno
need to transform hit into target
im so confused what this is supposed to do
you want to go into the else if? which has the same logic?
yes!
but it's a spherecast now
the whole idea is to scan for several targets
this piece executed several times
so if it's cached, discard the raycast result?
you could have these be separate ifs that check assumed_target == null (and you'd do assumed_target = null in the cached check)
but it'd probably be more readable to just have this be its own method that does returns
not sure I understood first one but this surely works and look bit suboptimal
private bool IsDuplicate(RaycastHit hit)
{
AggressionTarget assumed_target = hit.transform.GetComponentInParent<AggressionTarget>();
if (cached.Contains(assumed_target))return true;
else return false;
}
this would duplicate the GetComponentInParent call wouldn't it
🤔 wait this also does nullcheck
yeah it is suboptimal
it doesn't
right
well I can put one assumed_target there as an out parameter
and it will be godawful design to look at
you're overcomplicating it
just pull this if tree out into its own method and put in returns in place of the assumed_target
Maybe don't make the second condition an else and return early if you've found what you need in the first condition
On some random article about UnityEvents vs. .NET Actions. I don't think I quite agree that using Lambda method is "cleaner", it just obscures stuff.
I think it's way more "consise" to do subscribe on Enable and unsubscribe on Disable
Lambdas are disposable and anonymous, so, they could make the code cleaner for things that are meant to be disposable.
I see, any examples where I'd want something like that to be disposable?
callbacks rather than event listeners, perhaps
Example, you want to one-line destroying every game object in a list:
someList.ForEach(ob => Destroy(ob.gameObject))
The entire point of this line is to shorten a for loop into a single line, so making a bespoke function just to destroy an object to pass to that Linq function would be counter-productive
Ah that kind of syntax exists in C# as well huh
I'm familiar with this kind of thing in JS
that's what a lambda is
many languages use this term for what js calls arrow functions/anonymous functions
(what did you think it was...?)
Yes it's an arrow function in JS, but IIRC there is no syntax like
foreach (var item in items) {dosomethingwith item}.
It's always an arrow function in JS
Okay forget my message then
most modern imperative-ish languages have both functional patterns and imperative patterns for this kind of thing
Crazy how I didn't learn about the existence of "for of" in a JS course...the teacher only told us to use foreach =>
Did you mean to compare c# events with UnityEvent? Delegate types are related and used by both.
(fwiw it's for..of that's the equivalent to foreach..in in c# here, for..in is kind of a different thing, closer to reflection)
and as pointed out, lambdas are also related and can be used by both
I feel like the comparison to JS is dangerous because in JS arrow functions capture this when function(){} does not. Same for the difference of what for of and for in does.
basically js fucky dont look at it
Ive never done a shop menu before
Where do i even begin with that?
Can someone give me a beginner level idea of how a shop would work
code wise
Where do i even begin with that?
drawing board - design out what it needs to do, what it needs to interact with, what it'll look like, what parts it's composed from
one of the massive decisions you have to make early is if you plan to use uitoolkit or ugui
i know what i want it to look like visually, im not sure how to convert that to a solid idea code wise.
like i have a grid of icons (items) that populate based on what the shop is selling.
but clicking an item would... trigger an event i guess or
the player would have a list of availible equipment they could choose from, and buying from the shop would add this item to that list
what are either of those?
if youre planning to build UI for your game you have to start off by researching how UI works in unity to begin with
UGUI is unity's older UI system. It's GameObject based, so you create a hierarchy in your scene to represent each part of the UI.
UIToolkit is a newer system that's used a fair bit for the editor's UI. It's not GameObject based; you create documents (either with the interactive editor or via code) and then render them.
UIToolkit is very similliar to Razor if you have some experience with it
basically imagine it as html and css for your UI
I am mostly familiar with UGUI
yeah, UITK closely mimics the flexbox layout system used in browsers
UGUI has its own auto-layout system (which is in the same ballpark as flexbox layouts)
What does this error mean? NullReferenceException: Object reference not set to an instance of an object
Ball_hit_bumper.OnCollisionEnter (UnityEngine.Collision collision) (at Assets/Script/Ball_hit_bumper.cs:42)
UnityEngine.Physics:OnSceneContact(PhysicsScene, IntPtr, Int32) (at /Users/bokken/build/output/unity/unity/Modules/Physics/ScriptBindings/PhysicsContact.bindings.cs:45)
null is the absense of an object. you tried to use something that doesn't exist
It means something on that line is null but you're trying to do something to it anyway
check for stuff before . or [] on the line mentioned
Score_Manager.Points=Score_Manager.Points+10; this is the line
Something on that line is null
Try using logs to find out what
it's Score_Manager
!code
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 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.
my two scripts I want to comunicate. https://pastes.dev/nLzGGqyvwT https://pastes.dev/UX16qFOHyz
Drag in Score_Manager
Into the inspector on your object
I was hoping to keep the Score_Mansger on a diffrent object to keep it from reasetting when the ball is desroyed
I didn't say to add Score Manager to this object
I said drag it in to the inspector
The public field
You have to tell it which Points_Manager you want the variable Score_Manager to hold
so like this?
No
On the object that has the variable
Drag in the object that has the script you want to reference
like this?
This is the object that you want to reference
yes
You have to drag this into the object you want to reference it
No
Literally just look at the inspector for your script
it will become obvious what you need to do
it worked
!learn you should consider going through the basic courses so you know what words like "inspector" mean to save yourself a lot of time in the future
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I will. This is just a project with a due date so I don’t have the time rn.
you don't have the time to learn a basic core concept? that'll just waste more time
Actually learning will save more time than you lose to just randomly smooshing concepts together until it happens to work
should i be using IEnumerator coroutines or Awaitable (or Task?) methods
any guidelines on when which one should be used?
it feels like both are very similar but i find enumerator coroutines to be a bit clunky and unintuitive
there is no exact way to answer this, there are only pros and cons in each
Coroutines just make it easier to work with specific unity apis cause only work on main thread since they are mostly not-thread safe
I have done most of the ball movement one which would be most helpful for my pinball game project?
now the Awaitable is a better solution to Tasks for Unity API , cause at least you can temporarily switch it to Main thread if a unity API is needed to be called in the thread
there is also UniTask which is a bit more mature than awaitable that some people still swear by it.
But it is third party
basically what i wanna do is just have an ability i can call with a single method and that one method to contain all the stuff like starting the cooldown, playing the animations, spawning projectiles, and ending the casts etc
not sure how that relates to async
well im gonna need to wait for some seconds and whatnot, since the casts take time
async is better for thread blocking operations such as IO and Network / performance boggling big operations
so should i use ienumerator coroutines instead?
You can do timers with all three, but I think Task.Delay doesn't seem solid for unity frame loop
there's Awaitable.WaitForSecondsAsync and EndOfFrameAsync
I'd use Update or just a while loop with a coroutine
true though personally I do not like those Wait method because you cannot mess with progress
personally I think deltaTime way is better if you're showing progress bars n such for the timing
so Update or Corouotine with a while loop (time.deltaTime)
but you can probably use Awaitable too with while loop but calling Unity api methods is still a pain inside of it
What would be helpful for me when making a pinball game?
im a bit confused, would something like Instantiate be part of the api methods that would be painful?
yes thats part of the unity api on main thread
unity essentials
!learn
but...I think this works ? https://docs.unity3d.com/ScriptReference/Object.InstantiateAsync.html
@maiden totem
The operation is mainly asynchronous, but the last stage involving integration and awake calls is executed on the main thread. 🤔
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
seems reasonable?
im gonna try awaitable, if something seems very off ill switch to a while loop or whatnot
I'd expect that this still needs to be called from the main thread since they didnt specify that it is thread safe
Havent tested tho
yeah true. I havent used it myself so you may be right 100 here
maybe fiddling around with threads isnt the best idea then
I just mean while loop is alt to Wait seconds methods or Task.Delay
On the main thread I think coroutine vs. Awaitable would be very similiar
I like the Time.deltaTime approach to sub/adding number timer cause like I said its easier to do progressbars
I don’t see any called unity essentials
Nothing you said you want to do warrants using a background thread
are ienumerator coroutines background threads as well?
No
okay then i think im safe to use those for this
also this is probably a stupid question but i've seen many different opinions and im not sure about it, but is encapsulation worth it? I've been doing stuff like [field: SerializeField] public int variableName { get; private set; } for a while now and is that... too much?
definitely not "too much", that's not rare
it's appropriate for something that anyone should be able to read, but not change
I don't like serializing the auto-generated field though
(i guess because it makes renaming the property a bit more annoying)
obviously, you can use [FormerlySerializedAs] so that existing data doesn't break
but now you're stuck with that forever unless you ensure that all uses of the data are updated
this would be particularly bad for a package that other people depend on (it's easy to make sure your own data is uploaded, but other people's? oof)
using an explicit private field separates the name of the serialized property from the name of the...property
(name collision!)
Is it necessary to complete the entire pathway course to get started or can I learn on my own project?
(How did you guys learn to implement movement and customize it to make it your game
@swift crag @naive pawn
dont ping people randomly
nothing is really necessary but if you are new to unity then yeah the entire essentials pathway is recommended
no no they were on the topic thats why I pinged them
also okay
hey I'm new to coding I tried using the C# tutorial for the driving (since I'm trying to make a driving game) but I'm using my own blender model and for some reason when I use the script on the blender model it doesn't seem to work but it works on the car I got from the package. but when i go into play mode (with my blender car) it doesn't go forward when I press W and S instead it goes side to side and acts as there is a barrier Infront of it I have searched countless of times for the what the issue could be and I don't get the answer (no the car does not have wheel colliders it has Ridgidbody and a box collider but could someone please help me out on this?
so the car from the package
is it just a model?
or is it a prefab
if so the car might have some other things set up on it that yours doesnt
the car from the package is a prefab. the car i made is also a prefab
maybe if so is there anyway i could check?
well it almost certainly points to that being the issue
take a look at their prefab
open the prefab up and check out the object hiearchy
see how its set up
mimic that with yours
okay
to be honest i think i tried this but i was kind of stressing so it just flew over my head
the only difference is that it has a front angle at the front of the car
other from that everything seems to be the same
so the object hiearchy is indentical?
the only difference is the mesh for the car?
are you 100% positive?
i opened it and it took me to a blue room with the car in the middle and im sure thats the only thing
thats not really telling us much
yes
thats why i specifically mentioned the object hiearchy
can you screenshot both prefabs opened up
sorry
the hierarchy and the inspector
wait do you want me to click on the arrow next to the name of the package?
no im telling you to open both prefabs up in the prefab view
expand the hiearchy fully and screenshot the root objects inspector
for both prefabs
im sorry but im kind of confused 😭
wait ill take a screen shot of what im seeing right now
I can handle the GUI part , i know what i want my layout to look like.
My issue is how to handle the shop,
okay sure i have a button for "buying" an item but what does that... mean?
Im not sure where to start.
Id have a prefab for the ui object , referencing a scriptable object?
Then i guess i add that to a list of "owned" objects.
As for UGUI vs UItoolkit i just never called it that so not sure what you meant, ive always used UGUI. Wasnt aware there was a new system.
UI toolkit sounds really cool imma have to look into that
you said there is a rigidbody, where ?
i removed it by mistake
theres
what about your prefab?
so is the movement based on rigidbody how do you think it should move without one
so they are not identical....
in the slightest
even after i asked you twice if you were sure
bro.. i could of sworn i added colliders and stuff
the collider is the least if the problems if its not moving..
i forgot to save thats why it didnt have colliders
hold on let me just fix this real quick
alr i inported my new go kart
ive made it look a bit more identical
the wheels fell off
it moves but it just goes side to side and acts as theres a barrier Infront of it
can you clarify what that means?
it doesnt move forward?
Did you add the Front_Angle collider from the original prefab to yours?
perhaps its related
what is the code that moves it
nope but i think i need to
i tried to but i just dont know how to
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 10.0f;
public float turnSpeed = 25.0f;
public float horizontalInput;
public float forwardInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// This is where we get player input
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
// We move the vehicle forward
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
transform.Rotate(Vector3.up, Time.deltaTime * turnSpeed * horizontalInput);
}
}
this is overriding physics, it shouldnt even be affected by colliders
// This is where we get player input
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
This is cursed
the only thing cursed about it are the variable names, other than that nothing is wrong with it
well besides unity making you use Translate instead of AddForce/Velocity on a RB
i mean i pressed play and the wheels just fell of lol
can you clarify litterally anything you say please
huh? do you have a rigidbody on the wheels ?
input capture has 0 to do with collision
yes i do
yeah thats wrong
does the original prefab... probably not right.
idk i tried it in something and it messed with colliders, could go through walls
wdym?
does the original cars prefab have rigidbodies on all the wheels?
the only reason it would go through walls has to do with Translate as its moving the transform directly and bypassing physics
not directly input related
oh ok
yes i believe so
so the red car i showed you guys?
if you have rigidbody on wheels and colliders on them too, they will act as seperate objects from the main rigidbody causing to feel as obstacles
they do not have rigidbody on the wheels
but again , Translate should in practice override obstacles anyway
to add it
we're not getting the full picture here.. its kinda confusing
if the car that works
doesnt have rigidbodies on the wheels
what does that tell you about your car that has rigidbodies on the wheels
holy shit im a idiot
please use logic, reasoning and deduction
bro i am sorry
https://chenglou.me/pretext/variable-typographic-ascii/
i have a question,any idea how to recreate this filter in unity?
Proportional ASCII art driven by a shared particle-and-attractor brightness field. Georgia at 3 weights × normal/italic vs monospace comparison, with characters chosen by brightness and measured width via pretext.
you dont have to apologize, but youre not exactly making it easy to help you
plus as nav said we are still missing some context here
shaders probably?
if you want us to help you, you kinda need to actually try
the wheels still fall off
cant even say anything against this lol
okay, now for the third time
what does this mean
unless you have rigidbody with gravity on them, wheel shouldnt just fall off lol
how bout the font tho? i tried make it using monoscript and it takes so much
wait i forgot to turn them off in prefab
i want to reply to this but i feel if i do i would make myself look more of a fool
i turnt off the rigidbody on everything and it stays in one piece now
that the wheels aren't attached to the car as a child?
Monospace = easy but ugly. Proportional = nice but expensive
okay so now the car only goes side to side
we are back to square one
do you guys want me to send a video on what i mean with the car going side to side?
can't you just remove the rigidbody from the wheels and attach them to the car as a child?
dude imma be so real here im new to unity so that sentence as a whole just dont make sense
im new too
which is kinda why ive been taking long and being dumb (not because i want to be dumb buy because idk what im doing)
how long u been doing it for?
almost 2 months
ive been doing it for a week
I think you should follow the video / tutorial exactly before trying to do these customizations
understand the workflow and components a bit better
if I'm learning the last thing im gonna worry about is assets and how they look
you should check out GameDev tv beginner course tutorials, that's what im following
i mean the only reason im so worried about the go kart being the car i drive is because my friend made it so when i show him how stuff is going with the game he can see im using it
i will check him out thanks for the suggestion
@scenic raven
yooo
you see the player rocket in the hiearachy, it has a "spot light" attached to it
so wherever the rocket moves, the light will be attached to it so it's always lit up
when you make a new thing in the hieararchy you can drag and drop it onto another thing and it becomes the child of the thing you dropped it onto
what is expensive? is it takes performance?
and when you adjust it's position you can adjust it relative to where the parent is, so it will remain relative to where the parent is
okay so like this
if i drag something into my hierarchy i can drag something ontop of that making it a child
so if you attach wheels to a go cart you can prefab the wheels then attached 4 of them and called them "FL wheel" "FR wheel" (front left, front right)
rename them then adjust their position relative to the parent
so if you want to attach something to another thing, the thing you're attaching to is the parent
and the thing that you are attaching is the child
you're dragging something to the parent, it then becomes the child
yes i had something like this in mind but didnt wanna say
not horrid but I believe only cause you need to measure different widths unlike monospaced. I'm not super versed on this topic though , I haven't done something like this yet so maybe its a more complex topic for #1390346827005431951
so when I adjust the position of the lasers, they shoot from the same point of the ship all the time
alr i understand it now
it doesn't go to the crosshair yet but you can see the lasers are always on the same point of the ship, it's like you're literally attaching it to the ship
yeah i see
want me to send a video on my issue
because i feel like once i fix this
then i can do a lot more stuff
when you adjust their transform make sure these settings are "Pivot" and "Local"
yours was set to Center when u screenshotted it
i prefer center
its not good to use center positioning things especially in code, its misleading
ight, thanks
oh really?
the pivot could be 20 miles away but show you have it close. then if you do something from transform.position you wonder why its not even doing it from there
center is only good for mass rotating a bunch of objects so they dont individually rotate
and a few other specific reasons, in most cases should always be on pivot so you know where origin is
send a video of it or screenshot
hold on
wait should i add the script to it in the prefab
no
i shouldnt
thats a dumb question
I want to see what's going on lol
if the car is meerly visual the script only goes on the main object
that error is unrelated to anything in the play code
i dont think so
its the editor bugging out / layout
i really dont know
thats why im telling you
the script should be on New Prefab 1
no the editor is fine
it is
so whats the issue cause the video doesnt show any
Did you check to see if all your scripts and [SerializeFields] are still attached / have things attached?
do you have a [SerializeField] somewhere which you need to attach an object to in the inspector?
nope
the car doesn't move
does anybody know how to code a gorilla tag fan game computer?
send the current script and what other components are on New Prefab 1
sadly yes..
sadly?
gtfg is brain rot
How is it 'supposed' to be moving?
the only component is mesh collider
WASD keys
you said the script was on New Prefab 1
can you make up your mind
yes it is
sorry man im super tired
can you show the movement script
the script is only on prefab one and thats it
screenshot it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed = 10.0f;
public float turnSpeed = 25.0f;
public float horizontalInput;
public float forwardInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
// This is where we get player input
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
// We move the vehicle forward
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
transform.Rotate(Vector3.up, Time.deltaTime * turnSpeed * horizontalInput);
}
}
ok so when you press buttons WASD, do you use Horizontal / Vertical input go to > 0
You marked this as Environment static, of course is not gonna move...
im a idot i swear down
Pekal i think you need to actually start learning some editor basics
i lowkey got to go bed man 😭
i didnt even mean to make that static ibr with u
if you're tired go to sleep, its never good to learn / do highly mental processing tired
yea look into the GameDev tv beginner courses, that's what I'm following, they're well structured
going straight into making a game is kind of like just doing things randomly
thank you so much for all the help ik ive been a pain in the a$$ but i really didnt want to be i haven't made this easiest thing and i apologise for that
u sure man
i wonder how this helped u learn
Just trying to solve different problems is helpful
ooh alr
anyways im going to go bed now since im half asleep
gn
again thank you guys for the help and goodnight
I have an inventory system & need assistance with it
I have a public abstract void OnEquip and OnUnequip with the same keywords on an Item class
They have different parameters for each of the subclasses (Consumable, etc)
How would I have a script to call those methods and have it know which parameter to pass in without having:
if (class == "foo") {} etc
I tried searching it up and i didn't find anything
I considered having a big table to be passed in every single time but that would pile up on every special "custom" item and waste a ton of memory
yeah breaks polymorphism hence the ugly class == use a shared ItemContext object or something
or maybe try doing this with interfaces
i did the context before, but i figured that there will be so many things piled up in memory that it wouldn't be worth using
i don't want my project to be a triple A computer part requirement slop game
normally a valid concern, here inconsequential tbh
depends how much in it...a few references maybe? probably would be what like 50 bytes per instance?
at least in the context of an inventory it doesnt sounds like you will hit extreme case
even at 1000 contexts per frame thats what? 50 kbs ?
if allocations are a worry at worst you can pool it / reuse the same obj
keeps it simple enough imo.. if behaviors are truly unrelated, interfaces are the option too
I'd only worry if profiling shows heavy GC pressure
i'll try this after i eat thanks
The itemcontext could be a struct to avoid allocations, and pass it with ref or in modifier to avoid copying, but yeah thats a bit above beginner level
ref = read/write, in = read-only
Could you demonstrate the struct
It would have the same contents if it was a struct or a class
So all possible things (references, values) that might be needed to pass into the method, like nav said
Okay thanks so much
don't ping people randomly.
hey everyone, I'm having an issue with data being loaded.. everything seems to work except for one file and it's the statistics script.
when i start up the game all the data is reading with "0":
savefile before loading is:
"StatisticData": {
"ActiveTiles": 0,
"InactiveTiles": 81,
"TickCount": 75,
"AllEnergy": 215,
"AllCurrency": 0,
"AllPlates": 0
},```
savefile after loading is:
"StatisticData": {
"ActiveTiles": 0,
"InactiveTiles": 81,
"TickCount": 0,
"AllEnergy": 0,
"AllCurrency": 0,
"AllPlates": 0
},```
this is where it's being called:
private void Awake(){
#region Instance
if(instance == null) instance = this;
else{
Destroy(gameObject);
return;
}
#endregion
#region Save/load test
_cells = gridManagerObjects.InstantiateCellGrid(startMatrixSize);
SaveData loadData = SaveManager.LoadGame(SaveManager.saveName);
if(loadData == null) {
}
else {
LoadCellData(loadData); <<----- LOADING PREVIOUS SAVE WITH ADITIONAL DATA WORKS GREAT
SaveManager.SaveGame(SaveManager.saveName); <<------ THIS IS FAILING TO SAVE THE NEWLY UPDATED LOADDATA
}
#endregion
}```
You'll have to show the code for LoadCellData and SaveGame
why doesnt this work?
Because unity projects don't use main as an entry point. It's not a console app.
Might want to learn the unity basics in addition to C#.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
I changed line 4 to void start() but it still doesnt appear in unity console
I alr enabled the script on my game object
void start() or void Start()?
unity doesn't use Console
also what nitku said
I akso changed it to debug log
if you're following a plain c# tutorial, run it in a plain c# environment (eg, not unity)
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 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.
Console.Log doesn't exist anywhere i can find either, did you follow a js tutorial or something
or are you just winging it
anyways, configure your ide as well
!vscode
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
so I made a simple class
(AggressionTarget is an interface btw, is this the issue?)
[System.Serializable]
public class AssignedRocket
{
public AggressionTarget aggression_target;
public Vector3 last_known_target_position;
public GameObject pointer;
}
public List<AssignedRocket> rocket_setups;
and I try to do this
public int amount_of_rockets = 8;
void Awake()
{
rocket_setups = new(amount_of_rockets);
}
and it just does not work, list is the same empty thingie in the inspector
despite I can see and populate this list in the inspector in the editor
what's going on?
Let me assume, if it was a struct that won't cause issues, but if I just try to make classes out of nowhere it doesn't work like that?
(AggressionTarget is an interface btw, is this the issue?)
yes
but if I just try to make classes out of nowhere it doesn't work like that?
no
the built-in inspector doesn't draw interface fields
technically it can serialize references (if you mark it serializereference) but you'll need other ways to set the reference, iirc you could make a custom inspector for example
the odd issue is
as you can see from the screenshot
I can populate list from editor
but... can't through code?
is this so? is it's right, I don't understand why
like....
rocket_setups = new(amount_of_rockets);
that does not even do what setting 8 in the field of the list in inspector would do
that I can't see it in the inspector is not an issue for me
yes, because that's not what it does?
the int parameter is capacity
the number you see in the inspector is length
those are different things
I suspected that
if it was a struct instead of a class I would instantly see it populated in the inspector tho?
no
if it were a struct, nothing in what i just explained would change
length and capacity would still be different things
so.. is there a shortcut to create a list having some default elements?
alright
,“What does cross-posting have to do with this? I posted this to figure out how to fix the issue—what are you talking about?”
crossposting means you waste your own and helpers' time because conversation is split. just post in one place.
you didn't actually provide any info, nor even a question the last time you posted
“Okay, do you know this issue?”
you didn't even say what the issue was
go provide context where you asked originally
this is a code channel
It doesn't have to do with your issue but it does have to do with you. Ask your question in the channel it's relevant in and only there
is there any doccumentation/method to have loops only go to the next iteration when the user clicks the mouse?
Don't use a loop, take the body of that loop and put it in a function, then call that function when you detect a click
you could theoretically use a coroutine for that, but it could just make the overall code flow harder to read
tyty 🙏
Why do some peple use should for example shouldContinue variable?
It's just a way to keep a consistent naming convention for a bool flag
isSomething and canSomething and shouldSomething, they just imply what the variable represents.
if it was just Continue it sounds like a verb and should be a function not a bool
You can do whatever you want, as long as you're consistent with your naming conventions so you're not trying to read through randomly named variables trying to remember what they do.
where canContinue clearly shows its some condition blocking something else
Because they want a variable named that
Anyone building with Xcode and finding your .app is signed but not notarized bc its not happy with Unity frameworks? seems like its beefing with GameAssembly.dylib and UnityPlayer.dylib
my apple dev account is good but im wondering if anyone has ran into a similar issue. seems like the recent PLA might've broken something
so it goes side to side when you press w and s? or when you press a and d?
when i press W and S
that means the cars rotation isnt correct
when i press A and D it turns
also kuzmo i read back last night and i was being a pain in the ass which im sorry for i was super tired
i told you you dont have to apologize to me
in the prefab its rotation is 0 0 0
alr alr
try changing the Y axis rotation by flipping it -90 degrees
see if that makes it behave correcty
also check the original prefab
compare how the 2 cars are oriented
see if it really is the orientation
i have done that
ok ok
whats oriented?
okay do you mean the car that works?
yes
its 0, 0, 0,
so when you place it into the scene normally
how is it oriented compared to your car
its looking forward
if thats what u mean
forward is entirely arbitrary
relative to your prefab
are they facing the same direction?
let me check
just add it to the scene next to yours...
the same direction?
yes pretty much
offset the rotation of the mesh on your prefab
by rotating it -90 on the y axis
or +90
when i do it 90+ it faces right
i feel as if ive given you all the steps here to fix your issue, and you can extrapolate from here.
become smarter 🥹
when you select an object, the handles will show you its X/Y/Z axes (as long as you've got your scene view set to Local, not Global
the blue arrow is its forward vector
the model, which is parented to the prefab, must be rotated to align with that arrow
I might be getting it wrong, but hear me out
so I am instantiating a MonoBehaviour which is inheriting from an interface
then I instantiate an interface variable
then I assign that MonoBehaviour there
then I Destroy MonoBehaviour's GameObject
then interface variable is... not null, somehow?
I am confused
Destroy destroys the actual object in unity
the MonoBehaviour is not the actual object, it's a c# wrapper
you can't do something like, "make everything that points to this object null" - instead, unity makes it an invalid Object, but not actually null
unity's null check also includes that "invalid Object" state, if you're using a different null check it'll only check for actual null
you're not using the overridden == operator at that point, you're using the default == from System.Object. cast to UnityEngine.Object if you want to check for unity's fake null
here's some more info on it with examples: https://unity.huh.how/unity-null
I am using ==
but what are you using it on?
interface, yeah
right, but as i explained because you are using an interface type you are just using System.Object's == operator, not the one from UnityEngine.Object
if it's on a variable that isn't UnityEngine.Object then it isn't using UnityEngine.Object's definition of ==
i mean... kinda
#💻┃code-beginner message
#💻┃code-beginner message
both of these tell you how
alr that works but it's extremely confusing
can Console.Writeline only show the text or can it be used for other stuff?
you wouldn't be using Console.WriteLine in unity since that doesn't print to the unity console
alr ty
hi, i have a problem with deciding what order in layer an object should have. I have like 2.5D style walls, right now i tried to set the order in layer based on the center point/lowest point in the GO - the idea was the lower the point the higher the order, but it doesnt work and i have no ideas as to how to render it right
This should work already with sprite renderers but I think sorting groups break this and only child order controls it
also not a code question: #🖼️┃2d-tools
i have a code that assigns the order
sorting order?
sorry the order in layer
that should work too, lower Y should be bigger though to draw in front
yea but if the wall is really wide then it creates something like on the right in the picture i sent
That kinda breaks with diagonal objects as can be seen in the screenshot
The rightmost object's Y is a bit below the one next to it
exactly
I think often people split objects into a couple of sprites in these cases?
May be best. Its not really something you can solve well without 3 dimensions
This kinda split would probably work well enough
(The split sides would have different pivots ofc)
so then it would be 2 GO and each would have its order based on the Y cord like it is now?
Yeah
or like 2 sprite renderers
I can't think of a better way atm, but you can research online
Yeah and that requires 2 gameobjects
Can't stack them
1 sprite on the parent, another on the child, should do it
ok thanks
ofttop but I ve been here asking questions related to steps how to make this for quite a long time now and making homing rockets finally concluded
Very cool!
Hey guys I want to make a cardboard cutout of a sprite for vr anyone have a tutorial or can help?
hi can anyone help am new
we can if you ask a question!
Hey guys, I ran into a problem with UI elements. I made a timer and score meter, but every time I close unity, they move? Is there a way to glue them in place?
Hey, it's been a long timesince i used scriptable objects, how do I reference them? I was thinking making a script which acts as a database for all the scriptable objects I create
That works but they work like any asset!
Serialised ref or resources or addressables
What do you mean by that I don't know those words 😊
just use [SerializeField] or public field and drag it in
https://docs.unity3d.com/6000.3/Documentation/Manual/script-serialization-rules.html
google will explain them more
Yeah ok that's what I meant to do
{
public List<ScriptableObjectEnemy> scriptableEnemyList = new List<ScriptableObjectEnemy>();
public List<ScriptableObjectSpell> scriptableSpellList = new List<ScriptableObjectSpell>();
}```
Using resources would let you load many assets in code like this a bit easier but a top level object to ref them all isnt bad
ok ty I'll stick to the basics
Guys im trying to build a game in which you survive in different castle rooms. Your goal is to survive 1 minute in each room but every 20 second something makes the environment harder to fight such as turrets or falling parts, and the player (a cube that can be controlled by imput) must avoid these. Now about the hturrets, if I want the bullets to reduce the player health (10, -1 for each bullet) on collision (and the reduction of health bar that is a default 2d square sprite, where should I put the script that manage the health and the bar size? Should i create a gameobject and insert the script here (as a logic script) or in a specific place such as in the bullet prefab? Considering that the bullet is a prefab cloned by the turret
Health belongs to the player so should go with your player data/on the player. Some separate player UI handles showing this health
your player can tell the UI to refresh
I'm instantiating a prefab like this :
Animator playerMonAnim;
playerMonAnim = Instantiate(scriptableObjectPlayerMon.monsterAnimVerso);
How do i make sure I destroy the previous prefab before instantiating another one?
Can't you just make some basic 3D objects, uncheck their mesh and tick the 'on trigger' collider
then write the code in there what happens when the player colldies with the box colldier, triggers an event
well the answer is "logic".
If you keep a reference to this created object then you can easily check and destroy an old one before creating the new one...
if(thingy != null) Destroy(thingy.gameObject);
Ty
I want to make a skill tree system but making a scriptableObject class and an instance for each upgrade feels like blowing the project window.
Is it ok or there exists a smarter approach?
Feel free to ping me.
It's fine if you do it smart. It's normal to have classes and instances of them. Think of custom MonoBehaviour scripts.
Some things to consider: Do they need to be accessible from the inspector? Do they need to be unity objects?
Yup! they are gonna be accesible from the inspector. And what you mean by unity objects here?
You could just simply use plain c# objects..
OK, thanks bro. will be back if ther ewas a bproblem
hey guys i’m sorry i don’t know where to ask this, but I made a custom shader for a wiggle effect, not too complex. issue is that when I use it on an image, it ignores masks. I’ve been looking on google but everything’s a bit confusing. does anybody know a clear/easy fix?
#1390346776804069396 for shader issues, you'll also want to provide details about the shader in your post
thanks! posted!
I want to preserve the values of a TextMeshProUGUI for later use.. I'm doing stuff in code where I save off some values like fontSize into variables but I'm just thinking.. surely it would be far easier if I could just save the entire TextMeshProUGUI component off.. as far as I'm aware, the TextMeshProUGUI class is a reference, does anyone have any ideas? something like Clone() or EditorUtility.CopySerialized? Like what does Unity do when you copy a component / paste as new? I feel like surely I'm missing something easy instead of doing font = tmp.font; fontSize = tmp.fontSize; color = tmp.color etc... for every field
you save it as a prefab. look up unity prefabs . . .
I'm trying to do this on the fly with a script. It would be a huge hassle to prefab every text box in the game. I solved it by using Instantiate on the tmp's gameobject to make a clone and it seems to be working fine
What's the difference between both of these functions
{
if (Input.GetButtonDown("Jump"))
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange);
}
}```
```private void Update()
{
if (Keyboard.current.spaceKey.wasPressedThisFrame)
{
rb.AddForce(Vector3.up * jumpForce, ForceMode.VelocityChange);
}
}```
First is the old input system. Second is the new input system. Both are polling in Update for input.
I was trying Unity Essentials and I had both the website and the In-Editor pop up open
and they both were telling me to write it differently
I think one is outdated
as they mentioned, one is the old input system, and the other is the new input system . . .
So im tryna use visual coding and i CANNOT get a player controller to do anything besides look around, please help me im going insane
Also im using visual coding because i refuse to learn c#
Thank you i did not see that oml
https://pastecode.io/s/i7x14i1t
Hi yall, can someone help me figure out why even if the reticle is perfectly on the enemy, it still says I lose?
Duel system for my game(needs some work)
The position of a RectTransform (reticle.position) is not the same as screen position. Converting it to screen position isn't that simple. In general you shouldn't have UI elements interacting with world objects in this way. It would be better and easier to just make it a normal object
If the element is anchored top left and it's not scaled, then anchoredPosition probably matches the screen position
Hey, guys! A class that derives from scriptable object class is by default a static class?
Because I dont have to create a field of this class in order to get a referencec and I was wondering
What I am doing is just do PlayerData.PlayerID.P1 in my case
instead of
yes then how I am able to get a reference through a class without even creating any fields of the class
I haven't created a static class myself so not sure
I'm assuming you're referring to an "instance" rather than "field".
Check
and yes
That is not a field that is a type
yes I cant understand
I dont have to create a field in order to get a reference to player id I am doing it with the instance of a class
So enum is not a member thats why right
what exactly?
The type isn't. You can have a enum member.
you can declare any type inside another type, that's just nested types and they can be accessed trough the type directly
So yeah is similar to static members since static members belong to the type not the instance
Im restarting my journey on learning how to code in Unity, and ive got a working player movement script, but i can't figure out how to make it to where the player's jump doesn't get stopped when they move... im not wording it right, but here's a screenshot of the relevant code.
Looks like you're confused between class members and nested types.
ard there any resources about the relative computational costs of putting things in Update? Or maybe some common "don't do this" type stuff for update()?
Likely you're not wanting to assign the y component zero if you aren't wanting to modify/override it.
what would i put instead?
don't modify the velocity directly for movement, this will override any applied force on the object
i can say, that you don't multiply by deltaTime when using force or velocity (i.e. physics) . . .
Cache the previous y component and assign that to it or modify only the x and z component of the velocity vector.
Yes
I want to understand
you're assigning the y component of the velocity to 0. that overrides the force you apply in your jump. instead, assign the current value of y from the velocity . . .
var velocity = rb.linearVelocity;
velocity.x = ...
velocity.z = ...
rb.linearVelocity = velocity;```
ok, so something like this?
I think those are good examples of that we were talking about or not?
when you declare a field, function or property without static or const, by default it will belong to the instance of that type, meaning you need to create a new instance or get a reference to an instance of that type to access those members
Is this a good example of what we were talking about
no, thats just ref types vs value types, this is irrelevant
ok
The problem was that I got a reference before
I have created a PlayerData playerData;
inside my player data class I had an enum
don't confuse reference types with getting a reference
Are you referring to the declaration of an enum type or an enum member?
Hi everyone! I faced a problem with behavior tree. I'm trying to make simple enemy AI, which see target, than move to it, that attack, but if target not in a enemy view, than return to patrolling.
I created 1 condition and patrol behavior action. And it work on way, that in start of tree enemy patrol, than when enemy see target abort is called and enemy start moving to target, but when player disappear from the target, enemy continue to chase enemy and never return to patroling state. Could anybody tell me it's expected behavior with my tree, and if it is, than how I can handle this?
mabye the enemy rotates towards the player and moves at a pace where the player is always visiblee?
I don't think so, because enemy have range and angle to see player, and when I debugged code, I realized that "Self can See Target" never revaluated again..
this is node what i talking about
Oh, i wonder if the self must touch the target for it to be marked as complete?
am i allowed to put visual coding stuff here cause i can not figure out why my code isnt working and no one is responding to me post in #1390346878394040320 T~T
nah just wait until someone does ig
danm ight
does normal scripting have an issue with player controllers where it moves diagonally backwards?
cause thats the issue im having and i have zero idea why
no
and this my action node
many ppl cant even see visual coding tab thats why ig
it's better to use paste sites for providing code . . .
!code
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 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.
Thanks for knowing, next time I do it your way 🙂
it's not my way, just the general way everyone shares code. most people cannot see embedded code in their discord, and no one will download random files to their computer . . .
yeah, I understand
yo i dont see a max chaseedistance var but mabyee it would work like this:
if (distance > context.MaxChaseDistance)
{
context.State = EnemyState.Idle;
return Status.Failure; // This lets the tree switch back to Patrol
}
Yes, but my patrol behaviour will start to know about the chase behavior, I don't think it will be good in the feature
I read this documentations previously, but it isn't realy helps to understand what wrong.
https://docs.unity3d.com/Packages/com.unity.behavior@1.0/manual/observer-abort-mechanics.html
Maybe I can't using running actions with abort operations, I don't know..
but self or both abort types must check condition while child node is running if believe docs....
!collab
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
<@&502884371011731486> seems like a scam to me?
?ban 548715125339586561 Scam bot
pcsotfsmedvescak8074 was banned.
It is
Does unity behaviour tree usable at all? I see abort node didn't works as I expected at all
Why behavior tree always running abort operation and never fail it? it restart tree and try this node again and again and again.
Shouldnt I use the canvas? that feels like itll make stuff easier to controll and makes more sense, also it's scaled, but i really want to use the UI
Well you can google for how to get the actual screen position of recttransforms (and specifically its center point) and try to get it working that way
in screen space overlay mode, position is screen position
Thank you!
what are the alternatives anyway? having alot of small canvases in the world? that's, like, bad?
or what did you mean saying "in this way"
I mean comparing the positions of gameobjects and screen space UI elements is awkward at best
Usually you wouldn't use UI elements at all or use world space UI elements for that. A reticle might be a special case but usually you'd just check the mouse position directly
I don't believe in most games UI markers on things are somehow unique
I ve severly upgraded someone's github solution to be able to attach UI objects to transforms and clamp it to edges and I don't understand why it's not supported by default
everything on one canvas I mean
world space UI would create canvases, right?
that's like considerably bad for performance
That's not what I'm talking about. I mean very specifically having a regular gameobject and an unrelated UI element and then trying to compare their screen positions. Not the general case of just having UI elements in the world space
well... yeah it's kinda pointless since one axis is missing
Screen position always has two axes
screen coords technically do have a meaningful third axis, idk if it'd make sense to apply that claim to screen pos though 😓
right
for some reason this doesn't work for me and i don't understand why
start by debugging
What are you expecting to happen that isn't happening
And why are you multiplying a fixed value by deltaTime
I'm trying to move my camera along the X and Y axis. earlier, it was working in a limited sense, because I was able to see it moving, but it would always return back to where it started, effectively locking it in place. now, it's not moving at all
Right now, you're setting the rotation directly to a specific value. That value's gonna be very close to 0 unless lookX and lookY are huge, because you're multiplying that fixed value by deltaTime.
This is what i have now, but it still doesn't work. I know that the Look() method is still being called on properly thanks to using Debug.Log(), but i don't have any camera movement.
You used debug.log and did you log the values ?
wait no i didn't i forgot to do that
+=
The values are a constant 0 now
i just checked
!code btw
📃 Large Code Blocks
Use links to services like:
https://pastes.dev/
https://paste.yunohost.org/
https://share.sidia.net/
https://paste.ofcode.org/
https://paste.myst.rs/
📃 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.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
what is lookSense set to?
in the inspector
it's lookX and lookY that are currently logging 0 no matter what you input, right?
if that's the case, how is that input action set up?
okay im an idiot, i forgot to add the mouse controls after trying to troubleshoot it earlier
but now its doing the teleporting thing again
which teleporting thing
yeah, i did after i got it to work, its currently set to 16 in the inspector
where would you use that
yeah they probably worded it weirdly, but assigning to the input*100 rather than adding the input to the current rotation would make it seem like the camera is snapping to randomish positions, which is probably why they described it as teleporting
that makes sense
New problem: no matter which way the camera faces, my player doesn't move in that direction.
how are you rotating the player
private void Rotate()
{
Player.transform.rotation = Quaternion.Euler(CameraHolder.transform.rotation.x, 0, 0);
}```
so, you know rotating around the X axis is pitch, not yaw, right?
also transform.rotation is not in degrees, it is part of a quaternion
https://unity.huh.how/quaternions/members
Don't read the individual components of a Quaternion. xyz and w are for advanced use cases only.
Hello. I've set my scrollbar value of steps in unity default packages
how do I import it to my current project
Wdym by "scrollbar value of steps"?
The amount of steps the slider has
Which is 11 by default
save it as a prefab
export the prefab
import in the new project
Is there a way to get the index of an enum?
cast it to int
That's simpler than I thought thanks
or whatever your base numeric type is for the enum (int is the default)
enums are just ints with masks on.
Alright ^^
In c++ we cry because we STILL DONT HAVE GOOD ENUM TO STRING AGH
As a beginner, would it be easier for me to use visual scripting, or should I just dive into coding?
I recommend just diving into coding. It will just get you farther and it's really not that much harder. It's a lot easier and faster to work with in the long run, IMO.
Alright, thank you.
First time using a switch in a method with a return thats not void, what am i missing here?
default: return null;
wondering why you are not using an array for the abilities though
would avoid this kind of verbose switch statement where you have to hard code every case
Thank you
+
Yeah great point.
I figured it wasnt need its just the 3 "slots" that i can drag and drop scriptable object abilities in to
so just checking what slot is what ability
yeah but what if u want to make 7 in the future then you have to go back and change a shitton
besides, if anything it's simpler and easier to code so there really isnt much benefit that I can see
Ohhh like if i add more slots you mean
Youre totally right ill just do that
Realizing that onMouseOver() is not going to work for my circumstances (if there is a collider in front of the collider I'm calling the method on, it just doesn't go through) so I'm wondering about alternatives or ways around this, without turning off layer interactions and such? It's quite annoying, it'd be nice if it like, returned a list of the colliders it's over or something rather than not logging it at all
thats why things like raycastall exist
I haven't looked into it a ton, but couldn't that get like, inefficient/take a lot of computational power very quickly? I will look more into that for sure though
cheap
versions that return array of objects is always best using the nonalloc variant, esp every frame
OnMouseOver is just a raycast you have no control over
Oh good to know, thank you!
