#๐ปโcode-beginner
1 messages ยท Page 357 of 1
whatever can we go back to original question
best way to compress samples to minimize disk usage
i am not going to attempt to help you with your absolutely dumb idea. so good luck
also your plan is still piracy. which is not allowed to be discussed in this server
i love others searching for excuses to kick me out of discussion
@late burrow Be quiet please. If you have more nonense to kick up, make a thread as always.
If they actually were solutions you wouldn't be posting here every day trying to solve another problem you didn't think of that literally would not be a problem if you just sent the bytes
hey guys, im trying to add an inputaction that takes a 2d vector as per a tutorial. but its not an option, probably bc im using a more updated version than the tutorial. any tips?
make sure you select the correct action type
well, let me send you a screenshot of what i mean
@rich adder as you can see, it doesnt offer me 2d vector
but, the tutorial does, you knomw?
yes because now it depends on the Action type you select
theirs has "add vector2d composite"
action type?
oh, you might be a genius, thanks
I need this script to return the dragged card back to where it began when we started dragging it not working not sure why it want to change every card to same position.
public class Card : MonoBehaviour
{
private Vector3 startPosition;
private int cardNum = 0;
private float distance = 0;
public void Start()
{
Player.cards.Add(gameObject);
startPosition = gameObject.GetComponent<RectTransform>().transform.position;
}
public void OnMouseDrag()
{
Player.activeCard = gameObject;
if(Input.GetMouseButtonDown(0))
{
startPosition = transform.position;
}
Vector3 mousePosNormalized = GameObject.FindWithTag(Tags.camera).GetComponent<CameraController>().mousePositionNormalized;
int cardLeftRight = 0;
if (mousePosNormalized.x < 0)
cardLeftRight = 1;
else
if (mousePosNormalized.x > 0)
cardLeftRight = -1;
else cardLeftRight = 1;
if (transform.GetComponent<RectTransform>().position.y > Screen.height / 4)
{
gameObject.GetComponent<RectTransform>().localScale = Vector2.one * 1.5f;
transform.GetComponent<RectTransform>().position = Vector3.Lerp(transform.position, Input.mousePosition + new Vector3((Screen.width / 4) * cardLeftRight, 0, 0), 10 * Time.deltaTime);
}
else
{
transform.GetComponent<RectTransform>().position = Input.mousePosition;
}
}
private void Update()
{
if(Input.GetMouseButtonUp(0))
{
transform.GetComponent<RectTransform>().position = startPosition;
GetComponent<RectTransform>().localScale = Vector2.one * 0.75f;
Player.activeCard = null;
}
}
}
GetMouseButtonUp runs whenever you release left click
Because every card is running this code:
private void Update()
{
if(Input.GetMouseButtonUp(0))
{
transform.GetComponent<RectTransform>().position = startPosition;
GetComponent<RectTransform>().localScale = Vector2.one * 0.75f;
Player.activeCard = null;
}
}```
It does not matter where the mosue is
OK so i changed it back it was like that but ow it throws null reference to and object then why???
it was not yesterday either the code worked for like week then one day decided to stop working
then I had o rewrite
I had to rewrite trying to fix it
Why does unity have this problem code goes for weeks working just fine then one day says no I am not working anymore?
Probably because a reference on the line the error says is null
how can it ba null i ahva enot nulled it
I have not nulled it
not like it dispeaing the card is still there and moving back otits position
not destroying it
What line throws the null exception?
things are null by defualt or if you assign them to null
which line
73
useful
OK your pinting out something but what?
Note the lack of line numbers because you did not post !code properly
๐ 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.
You said it is on line 73.
How do we know what line 73 is?
Doesnt even have 73 lines
nvm I going to the forums
Guys the child part is correct but it isnt working where did i go wrong?
Be sure to provide the stuff that is needed for them to actually help you
So I guess line 73 has an error because the code ended 20 lines ago
Pretty sure you can just use transform.position instead of transform.GetComponent<RectTransform>().position btw.
We literally can not see the problem
That's the issue
The problem being you refuse to actually provide the correct information yes
neither work all cards reset no matter what all go to parents position o matter what with Horizontal Layout Group
We answered that
I gave the orrect info lol not my fault the engine is buggy af
No, this is 1000% a you problem
You still refuse to tell us what line your error is on
I had issue the other day as wel and it was the engine I recoded that part of the engine and got the thing working, because it was creating random events all by itself because a prefab canvas not in use . I got same response I was the problem and not providing correct info when I shows exactly what Unity was showing me for an error. I wen to the forum had a responce in like 5 mins and it solved my problem.
Mate, you literally will not tell us what line the error is on
I can't help someone who hasn't developed object permanence yet
@dusty ridge Go the forums already. Otherwise, show the error so people can help you. If not, be quiet. If your next post here isn't anything useful to help you, you will be muted.
You are aware that we cannot see your goddamn screen right
The UI one is not called that. You should use TMP_Text not TextMeshPro
!mute 436401905392943105 1d You can return tomorrow. If the forums haven't helped solved your issue, you can ask again here with proper details.
mouse8763 was muted.
"I have an error on a line"
"What line?"
"This one"
"Which one"
"The one I'm pointing to on my screen can't you see that?"
oops
It truly is baffling to think people actually communicate that poorly
is..is that what he said?
oh he did
And yet, happens all too often
Can you stop spamming the !code bot as well, thanks.
oop you spammed it in the process but yeah
my discord was lagging so they all appeared at once on my screen.
Okay, i get it. no need to spam me with warnings now. Ironic considering you were warning me for spamming...
That wasn't me: #โ๏ธโeditor-extensions message
If you're having discord issues, that's not on us.
oh, its fine if its not you. but its not a discord issue. ive never been warned by any bot this many times
Was catching up with the server. You've spammed multiple channels. You can stop spamming now,
Yeah. I have. I explained it was an issue. Didnt need to get revenge on me by spamming me back though, okay?
Like I said, I was catching up from another channel you've spammed in
@fickle plumeThere were only two channels I even sent messages in. So again, no need for 7-8 messages, and if you were catching up you didn't need to do that. Pretty bad mod. But okay, just leave it there. Should maybe accept you're a bad mod instead of facepalming?
show code
one thing to note is that you should not be multiplying your mouse input by deltaTime. this isn't related to the issue but will cause stuttering issues so make sure to remove that and then reduce the value of your Sensitivity variable
anyway, look at the getter for your CameraY property
every time trust me
sometimes you just need a second set of eyes to spot a mistake like that
yes if you do not have an explicity backing field
you will need one anyway because right now you just throw the value you get from your Mathf.Clamp call into the ether
i'd recommend a cast with some volume like a boxcast or something. a raycast won't really account for ground unless the exact middle of the object is on ground
For slopes, you can check the normal of the raycasthit and use dot product to see the difference between something like vector.up and that normal is.
And yeah, rays can be tough with that
Volume casts are slower, yes, but it's not going to matter here at all
sure it would be like carrying 2 drops of water in your gallon bucket instead of 1
(and they're not that much slower, from my experience)
I prefer a 3x3 box of raycasts at each extreme of the bounding box. Then you can compare the distances between them all to find out things like the angle of the slope. But that's a lot of math
is this 3D?
if so, one thing to watch out for is that volume casts ignore things they start inside of
(you can configure this for 2D physics, i believe)
public override void OnPointerDown(PointerEventData eventData)
{
audioSource.PlayOneShot(click);
OnClick();
}
why isnt the code in here running?
im using a controller to navigate
Does your class have IPointerDownHandler declared?
Do you have an event system?
also if you're using a controller that meanw there's no pointer down
pointers are mice and touchscreens
im using the selectable class
what would i use then?
Really you don't need to override the selectable class, you can just have a separate Selectable component and then implement ISelectHandler or IPointerXXHandler yourself in your separate script
i thought Iselecthandler was for when you hover over something
im doing it because it makes setting navigation easier
I know I'm telling you a cleaner way to do the same thing
No, they're two different things.
The "highlighted" color on a Selectable is shown when the pointer is over the object
This is separate from the "selected" color
(both are incredibly faint by default)
public override void OnSelect(BaseEventData eventData)
{
audioSource.PlayOneShot(hover);
text.color = selectedColor;
}
Im using onselect for when the player is over something
for a controller there's no hovering
just selection
sorry yeah i meant highlighting as in selected
isnt the interface for clicking ipointerclickhandler?
You want ISubmitHandler / OnSubmit
having a bit of an issue with my IDE. even tho it's set-up and i'm using the appropriate dependency, it won't autofill/find any Unity.Netcode function, like OnNetworkSpawn or such. Am I messing something up?
try regenerating project files
what is null here?
do you have an event system active in the scene?
yeah
that just shows you have a GameObject named EventSystem. look at its components to make sure it actually has the EventSystem component on it
that didn't do it :/
if you type override first, do you see the NetworkBehaviour methods? because, unlike unity messages such as Awake and OnEnable, they are virtual methods on the base class
right sorry, its the autogenerated object?
and this object is already in the scene before the PlayButton's OnEnable method is run?
I do, i guess this does it. Weird tho, in the tutorial i was watching they just typed spawn iirc
yes, theyre both already in the scene
in that case are you certain you are looking at the correct line? the screenshot does not have line numbers nor the class name so that isn't entirely clear
can confirm
is this happening after loading from a different scene or is this the first scene you load?
this is the first scene
then i'd suggest using the debugger to step through the code and figure out why EventSystem.current is returning null
how can i do this?
thanks
what do i do here?
it shouldnt be
You probably don't have an EventSystem
I would like help with this still. The system will detect Vertices, but not edges other than their colliders being nearly identical.
Is it okay to have an Interface without MonoBehaviour inheritance contain member objects that are MonoBehaviours?
wat
well, an interface doesn't have fields..
but any code can work with MonoBehaviour-derived classes, sure
Something is weird with your camera object
^ ya thats a new one
I have two cameras, do I need to set something up with that?
before I updated, one just rendered the gun basically
as an overlay
I don't know what this is
URP adds this to the camera
if its easy enough to do i'd recreate the camera setup u have now that u've upgraded projects
i use multiple camera's in my URP project.. not really an issue.. just two things
- make sure only 1 camera is tagged MainCamera
- make sure that you only have 1 audiolistener
I've seen the editor have a little hiccup and screw up the additional camera data before
in urp you can use renderer feature
instead of 2 cameras? is that what u mean?
ive seen the same thing.. where it'll flicker.. like its trying to expand.. / recompile or something
sometimes u can click or and sometimes not..
i just create a new camera and delete ones that do that.. ihaven't seen that in a while tho tbh
2022 -ish
ok I think I've mostly fixed stuff but my clipping prevention is no longer working
I have the gun camera culling mask just set to UI so idk why it's doing this
ya, in URP u can use Renderer features to fix that issue
its not the same workflow as the 2 camera setup
yes: you can just directly draw an object onto the screen
you can do this after all of the other opaque objects have rendered, and ignore the depth buffer
yeah because you don't get shadows with 2 cameras
Camera stacking costs needless performance, and some developers go so far as to write their own shaders to produce the same effect without using camera stacking. In this tutorial I show you how to use Unity custom forward renderer (comes with URP) to produce the same visual effect as camera stacking, without having to add an extra camera to your...
yup this one helped me ^
The big-brain alternative is to just position the weapon so that it doesn't actually clip
by having the player pull it back towards their body
true, for him thats what id recommend.. my setup uses an extra camera for a render texture..
ill try it
camera stacking is old news..
still relevant.. but with URP u can save soem performance by not having an extra camera
renderer features in URP are dope
and like navarone mentioned.. u'd get better shadows as well
you can make easy outlines , see through walls objects etc
i use it for an outline shader
BUT. i been having issues with it so i removed it for now
gotta learn a bit more about the order of operations or w/e u wanna call it
yeah the rendering order and passes
yes, this ^
i already had it working but i dont like to lean on systems i dont understand too much
iirc if you look at the frame debugger you can see what happens on each pass
you can, not sure the procedure.. but ive shuffled thru them before looking at the cool stuff
like the depth
frame debugger is correct ๐
I've been trying to play with renderer feature to get an easy "obra dinn" look
so cool
i've had it lie to me before
to be fair, this is due to a weird SRP batcher bug
it fed wild values into a Matrix4x4 property that I hadn't yet set from a script
use the scrollbar at the top
but the frame debugger showed the expected identity matrix
ohh heck.. thanks
yea this one is sus.. not sure what its viewing from
the sun, perhaps
thats the best guess lol
i keep getting errors when trying to do the last line on startup. selectfirstitem is run onEnable, and im assuming the event system is not initialised by then or something?
Do you HAVE an event system in the scene?
What is the error?
yes. im getting a null reference exception, though.
doesn't look like a code issue. looks like you are using a non-humanoid animation on your humanoid rig
i'm not v good at unity, sorry how would i fix this
sry for wasting your time
also, it is a free asset from the asset store
have you tried looking at the settings for the animation?
no, that is the animator component.
try looking at the animation clips that the warning in that screenshot is telling you about
sry 1 sec wrong image
because that is still the animation component and not the animations themselves
wrong image sry mb
first of all !code . And if you rotate around your player and the player gets distorted in another axis then your up one, it will rotate around that new distorted axis resulting in weird angles
๐ 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.
nvm I got it working I just need to use a kinematic rb the code is working fine thanks you though
What is the best way to delete a GameObject after calling exampleGameObjectsQueue.Dequeue()
depends on what you mean by "delete a gameobject". if you want to remove the gameobject instance from the scene then just pass it to the Destroy method
Maybe I misunderstand but I thought I lose the pointer once I use Dequeue()
this isn't C++ (:
but yes, if that was the last reference you had to the game object, you will no longer be able to destroy it
(since you will have no clue where it is)
just pass the return value from Dequeue to the Destroy method
Hmm maybe
// do stuff
Destroy(foo);``` ?
yes
alright thanks
If you don't need to do stuff then Destroy(fooQueue.Dequeue()); of course.
Since you weren't saving the reference earlier, not sure if you need that. Just an idea
- that is backwards
- why, they never gave any indication of wanting to delay the destroy
- recalculate UV's in blender
- warped faces that bend/overlap
Please don't post incorrect answers
ive seen this before in blender (and unity alike)
basically a move command goes to a formation of units which in turn has to have a queue of formation positions for it to rotate at target and the move and then rotate again into position. No timer needed.
Are you completely a beginner.
I would say I am an amateur / beginner. A decade ago I made a simple 2d engine in C++ and I have enough understanding that my unity project is working as intended. Trying to use programming patterns and always learning a lot as I go lol ๐. Why?
That was a basic about movement and rotation.
oh, im aware of that trick.. i was just showing the shadowmap in the frame debugger..
the model's fine, I believe..
i got it from https://www.thebasemesh.com/
all their models have pretty good UVs right off the rip
I'm so confused lol
Don't worry about them. You're good.
What is the naming convention for public static variables in c#? I know that in java its supposed to be all capitalized kinda like this: public static float GRAVITY = -9.81f;
i usually use PascalCase for all public variables regardless if their static or not
camalCase for private.. and an _forLocalVars
I just finished my first year of computer science in college and ive been trying to adhere to naming conventions unlike what i used to do befgore college
really up to you tho, as long as its consistent
funny how it makes it clearer
well, its like color coding a file-cabinet ๐
once u file enough Due-Bills in an orange folder..
orange starts to give you anxiety
you can name ur variables whatever you want if it's clear and easy to read
haha
yeah i just look back on projects cause ive been doing unity for 5 years before college and im just like bruh what was i on
thats what you do in java i know that
and i also see alot of m_Gravity type variables for private members
but i think people are using that less and less often in Unity c#
Hello guys, can you guys tell me a reason on how can you pause an editor without pushing the pause button from the editor?
Because I don't understand how my script can pause my editor for no reason.
ctrl shift p
Ctrl + Shft + P
you likely have error pause on and have errors in your console
Cmd if ur trendy
what is error pause on?
means when a console error appears.. it auto-pauses
error pause
pro tip: leave it on and fix your errors
Thank you guys. Now it works. I have been rattling my head on this for hours now. I didn't know I turned it on by accident. I'm trying to make a behavior tree, lol.
That's right said.
if you leave it off remember to fix ur errors before u build
have you considered not ignoring the errors in your console instead?
but moooom....
The only error I can see is this though.
and I don't know what that is.
its some Mobile/ Android error
if i want to put a script in here to reference from how should i do so? like with codepen?
!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.
thank you
So does that error pause acts on what? Red errors only or it can also react on yellow errors??
the yellow ones are warnings, not errors
Red are actual errors.. yellow is warnings and white is just logs
red are bad
Red will break ur game.. hence why it pauses
ow thanks. I think the error in my console is about my phone not connected to my pc.
I have been playing around with the debugger for hours. I thought that my code has something to do with it pausing the editor. Lol.
yeap, it appears that way
If you dont connect a proper phone to pc to test the app, then go to player settings, editor, Unity remote, device, and select โnoneโ.
seems u can bypass that error while u work w/o ur phone connected
Anyway thank you guys. That was stressful lol.
i'm trying to activate pooled objects and they are supposed to be at coordinates 0,0,0. in the debug statements the position seems correct but in the inspector it's way off. I'll link the spawner script and show a picture of the inspector
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
The Position that the inspector displays is relative to the parent game object.
I know this is annoying but the Transform.position is global.
You're probably looking for Transform.localPosition.
are these objects parented to another GameObject?
yes they are

then it's as Lilac says . . .

position from the inspector is the local position, not the global position . . .
I thought about this a long time ago, but i sense a sighing remarks whenever you add those three dots. 
I also think i'm a bit too sensitive when it comes to tiny things, so it could just be me. 
3 dots means like a continuation of a thought
Hmm i guess it's up to interpretation. 
I always used them that way ๐คทโโ๏ธ
haha, no worries. it's not a sigh. it's a . . . wait, damn. navarone kinda hit it on the head . . .
Context wise, it feels like sighing against the obvious.
That's how i see it from months ago being here. 
it's like, "to be continued . . ." or a trail in thought. there are many definitions for it. my use is the creative writing version(s) . . .
Yes a continuation.

the parent gameobject is set to 0,0,0 as well. how can i keep the objects at 0,0,0?
And the parent of that?
And so on.
there are 4 levels of parents . . .
oh boy ๐

lol
any one of these that arent at 0, 0, 0 will offset all of their childrens' positions . . .
Understandable. I've rewrote something as much as 4 times.
https://docs.unity3d.com/ScriptReference/Physics.CapsuleCast.html
read the docs on what the points actually are for
the capsule moves along a direction. how will you determine what comes into contact with it, if it doesn't move?
like a raycast, you determine how far the capsule is cast . . .
horizontal or vertical wouldn't matter. both of those are directions . . .
is the height, the total height or from the middle to the top/bottom?
i asked because i don't know; just to make sure it's correct . . .
controller height is the entire capsule.. from the bottom to the top..
hi! is there a way to scale gameobject on instantiate? looked at api docs and couldnt find it
Instantiate returns a reference to the created object, just use that reference to modify its transform.localScale
and what if my reference is a prefab, and depending on what moment i want to scale it less or more?
the "reference" i was referring to what the object returned by Instantiate
your prefab is irrelevant
Instantiate returns a reference to the created object
!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.
oops
mb i didnt want to ping you
even though i was meant to paste code
do you mean something like this?
That is how you would set the local scale of the gameobject instance you instantiated
isnt that what i want?
Seems to be, yes
I am just explaining what the code you wrote does
okay
even though i still have to solve some unwanted mechanichs i think it is exactly what i need
how can i set a script variable to get a component(the script) from an object thats neither the parent or child?
No prob.
The question to ask is if the object exists before the scene starts or not
If not, then you'll either want to grab that reference from instantiate and pass it along, or get it from something like collisions
yes, in theory it should since the object from which i want the script is there at the start and doesnt get instantiated or something like that
Then best bet is to just drag and drop it
it wont let me do that
That is called "serialized references" in that link
Ah, is it to a prefab?
Prefabs can't reference scene objects
let me show you because it would be to large to explain for the little it is
brb
im back
if i want to drag it the tab closes and therefore i cant drop it
can i use the getcomponent even if its not a component from the same gameobject?
I'm confused what is going on here. You should click, HOLD, and drag.
If you release the click, it will select the spawner. If you don't, it wont
You could also click the lock on the inspector
Yes, but that is unnecessary here
OH i didnt know that happens if you hold
also you can pop out the properties for a component from the context menu or you can lock your inspector
It's the same click, hold, drag functionaility as all software I've ever used. Just don't release the click
ty all!
its my first oop language
well my first language at all
and same with software
Sorry, I meant software.
As in any program on any computer
Like the operating system itself
Like dragging a file into a folder
I got the tape but they don't have the rings in the right size and staples is closed so I'll have to get them tomorrow morning
I can't tell if this is super obscure joke or mistake
I kinda love it either way
okay i just tried this and it just doesnt happen, i want to move a component from the spawner to the "meteor" but i cant select the meteor for the tab to appear or i will lose the grab, and neither can i lock on the inspector since then i cant select the component from the other one
You can also drag the spawner game object, and will auto grab the component
ohhhhh
Oh, I see the issue. From the video it looked like you were trying to drag the object at first, so I thought you knew that
Watching videos of this stuff on a phone is difficult for me sometimes
oh no its just that the way my screen recorder works its hard to tell if it is recording or not so i was just testing lol
totally mb not yours!
np at all it was me doing weird stuff to check if it was working
how do you add linebreaks with appendalltext?
im currently using it and when it adds to the text file it is all in one row
Hey Guys remaking boxhead zombies, and Im working on Attack effects for the zombies,. WHen the hit connects, I want the player to be impulsedb ack a bit with an animation, in the direction he got hit. FOr instance the picture, like that direction, no matter what direction the player was facing originally. How can this be done?
How would I get all the referenes to scriptable objects of a certain type.
I want to get all the item scriptable objects ive made.
can you break moveTowards by lagging your game?
I have a moveTowards method on a obj that is starting to jitter and teleport after adding a asset from blender
Just want to say that it's an absolute classic, kudos for the design choice.
Also, consider doing Rigidbody.AddExplosionForce: https://docs.unity3d.com/ScriptReference/Rigidbody.AddExplosionForce.html
public void AddExplosionForce(float explosionForce, Vector3 explosionPosition, float explosionRadius, float upwardsModifier = 0.0f, ForceMode mode = ForceMode.Force));
Hey guys if I have a player class should I also put everything about the player inside that class or for example habilities or skills I should put in another class like PlayerSkills class ?
Avoid putting too many things into a single class. Done to the extreme, this is a bad pattern called a GodObject.
It's a matter of personal preference how much you should put into a single class. What matters most is readability and maintainability of your code.
If you have 1,000 lines of code in a single script, you're going to start having problems making productive changes. Separating scripts by their functionality is generally ideal.
I would recommend putting player abilities and skills in a different class than player movement, for example, since these serve very distinct purposes.
hmm ok, got it, thank you!!
Vector3.Normalize(player.position - zombie.position); //this gets you the direction in which to push the player
That says it does not return assets, so I'm not sure if that would work for SOs
Never tried it though. Worth a shot ๐คทโโ๏ธ
yee but ScriptableObjects are weird in the sense that it's an Asset of an Object (that function does pickup SO's)
Ah, it does. Ok good to know. Thanks.
same kinda vibe as Prefab's being kinda a single thing that's both an asset and an instance of said asset
Well, the page does SPECIFICALLY say it does not pickup prefabs though.
But I get your point about that similarity
Not really sure what you mean by the second part about prefabs though, honestly.
The blue objects in the scene are not prefabs. If it is an instance, it is not longer in the .prefab file format
I mean in the sense that in refering to them via code you use GameObject and ScriptableObject to reference both the asset and instance
can feel a little weird at times
Ok, I get what you mean. All just part of how reference types work
i guess
idk
I kinda wish there was some sort of wrapper class that houses them but Unity's way too deep in to even consider that change haha
An asset is an instance. A prefab is technically an instance too. It's just an instance that doesn't exist in the scene.
Everything is an instance of some type
Forsure, Would just be nice to have a built in way of knowing whats the asset and what isn't. I get that can't be built into the instance class c# wise but some sort alternative where the ""asset""" houses the instance used by the asset would be nice etc
far from a massive problem but
That would just add inconvenience imho. The way it is designed now is specifically for it to be convenient.
As for differentiating prefabs and objects in the scene, well, there are probably many ways, but it's all on you, the game developer.
Typically, you'd use naming conventions that make it clear what is a prefab.
I know you don't mean it like that but I feel like this answer could be applied to almost any piece of feedback/suggestion/opinion on a engine feature
The same page gives you a different line that does get assets: FindObjectsOfTypeAll
Is there a built in way to identify if a GameObject or ScriptableObject is an asset at runtime? aside from just handling your data in a way that manages it to be like that ofc
I guess so. In the end unity is developing the engine according to their vision, which is totally acceptable. They probably listen to feedback, but the fact that it is the way it is, means that there was not enough feedback for them to change the design.
Yes, that is the normal recommendation. To use the Resources class
For gameObjects, I think you can check their scene. As for SOs, it's hard to say. Need to research.
Ah yeah the scene ref would work
even something like that for both of them that's built in yknow
I know their meant to be as generalized as possible to not tie them too down to Unity itself but seems reasonable to have even some sort of enum property
For SOs, they don't really associate with a scene. Once an SO is loaded into memory, it doesn't hold any info on where it was loaded from(asset or created at runtime), so I'm not sure if there's a way to check it, unless you keep track of it manually.
yeeee. annoying for freaks like me who make them at runtime
Well, I don't see why you'd need that anyway
It's considered a not very great practice to instantiate SOs at runtime.
I totally get why doing it is bad but in some cases (espicially in prototyping and early iteration) it can save a lot of hassle when you have a chain of inheriting SO classes with default values that you wanna tweak in editor and drag into other SO's and prefabs etc.
in an ideal world i'd probably have a related base c# class that uses the SO to read data from but then i have to manage double the classes when i could just be awful and make a copy of the SO itself
CreateInstance would be a more preferable usage if you do want to create more instances as it'll use the default values of the original SO, so you can use it for something like a factory pattern.
It's not technically wrong to instantiate new instances of SOs, it just doesn't make too much sense and you might as well just new a plain c# object instead.
Yeee i do dw
Except I canโt (Easily) tweak the default values of a c# class in editor nor can I easily reference said class in inspectors for MonoBehaviours and ScriptableObjects
And yeah I can have 1 class for the template and 1 for the instance but as previously mentioned that becomes tedious when dealing with inheritance
Yeah that's true. I've done some stuff only with SOs like a Buff/Effect class before and it worked out alright
But that was me just trying new stuff out, but I've kinda developed my way to just use SOs as a readonly data parameter for a Mono/Poco object
Yeah very similar use-case, although for those specifically Iโve kinda found them more of a pain because Unity seemingly doesnโt have a great way to handle things like Moveโs which almost exclusively contain code unique to their class
At most, you can actually cut down the need for another Poco objec to insert that SO data for, but it doesn't work when you do need a Mono (like coroutines, but there's ways around it like a singleton manager)
Anyone know how to make player stop shaking when the elevator is moving up or down
Very common issue and there's many ways about it like parenting the player to the elevator, but I suggest you to research up your options
how 2 make some action to happen when catched any exception at any code location & send 2 this action exception text?
hey yall , im trying to use [ClientCallBack] but it isnt working (i am using unityEngine.Networking) was it changed because i cant find a changelog
Take a look at the AppDomain class
I believe it has an event UnhandledException you can hook onto. Hopefully Unity has not broken it.
Obviously this will not magically catch all exceptions and fix your code.
Ask in #archived-networking
i know about it, but how 2 get exception text?
I assume the event will delegate the exception to you, which contains a Message property
You can also cast to specific exceptions if you want to look for something specific
AppDomain.CurrentDomain.UnhandledException += (e, sender) =>
{
Debug.Log(sender.ToString());
Debug.Log(e.ToString());
};
throw new Exception("My own exception");`
don't worry about nullpointer, i'm trying 2 debug it
If it doesn't work then Unity broke it and you can't use it sadly
Which seems to be the case here
ok, so what can i use?
UnityEngine.Application.logMessageReceived is specially designed for Unity. Use string logString to check for the error thrown
Now I have mentioned that inline code block's appearance has changed
hey guys is Singleton Pattern a good way to go with my scripts?
If you're asking if all your scripts should be singletons then no. It's good to use it in situations where it's an appropriate choice but that's true for everything
Hey everybdoy, i wanted to ask if im developing a jackbox like game, is it possible to use unity relay or smth and two different unity projects? One for the PC and one for the WebGL build? Thanks n Advance!
why wold you need 2 different projects? Why not just 2 builds from the same project?
ohh that makes more sense. Thank you
what services would you suggest for me to use for this concept? Unity relay? and do i need unity lobby etc?
Only thing I can think of is to check if any log messages of type Exception are logged
But you should use this instead: https://docs.unity3d.com/ScriptReference/Application-logMessageReceivedThreaded.html
If Debug.unityLogger is mutable, you could even hook it directly: https://docs.unity3d.com/ScriptReference/Debug-unityLogger.html
But I doubt it is
Either way there is no proper catch-all solution in Unity AFAIK
If you want to log stacktrace of a message, you can do this inside the handler of your log BTW:
System.Diagnostics.StackTrace sTrace = new();
Debug.Log(sTrace.ToString());
This works because the stacktrace points to the calling method.
What's the purpose of direction in a circle cast
Isn't it just a circle with the given radius from the given point
the direction the circle is cast
you're thinking of an overlap circle. a circle cast is like a raycast, where it starts at the origin and moves in direction up to max distance
I had expected something like this
Hi can some one have a look at my saveManger please. It seems to work, but the more i save the more random destroyed items seem to come back https://gdl.space/xeliwumoji.cs
Where we just have an origin and a radius
again, that is an overlapcircle.
Probably go to advanced or general for this one.
cool thanks
hellp guys i followed up a tutorial on how to do a endless side scroller, but i wanna speed up how fast the obstacle spawn, kind of gradually speeding it up, i tried something and it didint work, this is the raw code anybody has an idea ?
!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.
if that is a screenshot of whatever you are using to edit your code then you need to get a proper !IDE and get it configured ๐
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
โข Other/None
no i use visual studio i just used one of the links from above, idk maybe this format is better https://gdl.space/unimazacar.cpp
yeah you're meant to actually share the link, not paste it into a site then screenshot it
my mistake chief im new in this boat
also what did you even try? this code isn't even going to move the object at all because speed is never assigned to
then some other code is moving it or you've changed it. because speed is private and not assigned anywhere in this class therefore it is always 0
yea it was supposed to be public ๐ญ
ok solved that issue, how about the speed up?
i asked chat gpt but it wouldnt go as smooth as intented
i mean, you just need to increase the value of speed over time
unless you mean how fast these objects are spawned, in which case you need to show the code where that happens
no, not how fast they spawn, it just how fast they move gimme a sec and ill repost it
then yeah, just increase the value of speed over time. that's literally all you have to do
but also i do want to point out that your original question literally said " i wanna speed up how fast the obstacle spawn"
https://gdl.space/akihideqaf.cpp hows this
ah mb
so the speed increase rate is at 0.1 and initial speed at 5 and thats what im getting from currentSpeed
so you want to increase the speed by 0.1 per second?
also keep in mind your log is printing for each of these objects in the scene
as a test yes but i think it just moves the obstacles randomly
i bumbed up the increase rate to 1.2 and they move weird hold up
yea the green cubes now move on their own i feel like to the right or something like that
that shouldnt be the case, i just want them to go faster to the left
kinda like how subway surfers increases the game speed
why don't you show what is actually happening
and the only way your code could move them to the right is if they are rotated so that their X axis points toward the left
let me guess, this whole time you wanted them all to be the same speed and increase all at the same time?
yes ๐
then say that. because you gave no indication that was the end goal
mb, i know i dont have the best english and my explanation can be vague
so now that you know that, how should i change the code
you will want something else managing their speed so that it can manage all of their speed at the same time. you could probably make the speed variable static, and have whatever is spawning them do the increase over time
i guess i ll sound dumb but its my first time going with unity and i have no clue what you said ๐
oh well time to search it up, thanks
Anyone have a good video on understanding Quaternions?
How would I be able to store specific data on a tile in unity?
Depends are you trying to understand the underlying math or just how to work with them?
You don't need to know the math to use them effectively
Underlying math, just to be safe.
Room list is not called, does anyone know why?
https://gdl.space/dicevokica.cpp
There's no safety in understanding the math
What am I supposed to look at? What doesn't work of all this code?
there is no safety in understanding quaternions
Can you be more specific?
To effectively use Quaternions in Unity all you need to know is they are a data type that represents a rotation, and they can be created and combined with the various functions in the docs
I'm trying to activate the function with a button, but it's impossible because it's just not called for some reason
Which function
OnRoomListUpdate
So what calls this? A button in your scene?
The function OnRoomListUpdate, for some reason...
I don't see anything calling this function
You know, I put the script on the object and then run it through a button
But you should not be able to assign a button to this considering the method takes parameters
Show how you set that up
Please show the button then
Also is there any reason for why Unity Editor shows different values for rotations and not just euler angles?
As you can see, the function does not appear there
Your question was why the method was not being called, not why you are not able to assign it
Please be more clear in your question next time
Yes we already explained why
You can't assign it because your method must not take parameters
Okay, so how am I supposed to get the function to call?
You don't pass parameterssssss
okkkkkkkkkkkkkkkkk
How is it supposed to know those?
Instead get the list in the method instead
Some things do accept parameters but not this one
And seeing the name of the method "On..." and the fact that it's an override, you're probably not supposed to call it yourself
Might be some event handler automatically executed by the library
Absolutely ^
honestly think manipulating the raw values of rotation makes more sense to my small brain than using the gimbal rotation thingy in the scene view. Like using the rotation ball is fine until you're values arent zero on more than one axis, then even rotating on one axis using the sphere affects the rest and my brain just shuts down ๐
That's because your tool isn't in local space mode, if the individual circles don't take the rotation of your object
At the top of the scene view are buttons that allow you to switch between modes, pivot / center + local /world
That has nothing to do with Quaternions though.
Is it possible to Assign references to scripts that are in prefabs so I don't have to assign them everytime I want to use a prefab?
My prefabs have scripts on them, but all the references are 'none'
So ... I'm a beginner unity user and not sure if this is the correct channel to ask this question. I made a game with a bunch of friends for a game jam where I just designed levels.
The game jam is over now and my friends have abandoned this project. I want to try to debug the game, but I have no idea where to start. Is there a tool that can help me look through the whole project and tell me where and how certain codes function so I can debug it?
As long as the thing you wish to reference is in the same prefab, or in your Assets, you'll be able to reference it.
I'm trying to reference another script but it's not allowing me to drag it into the slot in the inspector
You cannot reference things from scenes into prefabs because there is no certainty that the prefab will exist in said scene.
Yes, this is just how rotations work. It's because the rotation is relative to your parent.
Then what you're trying to drag is not compatible.
If you're dragging a script directly, then the variable type doesn't match the component type you're trying to reference.
If you're dragging an object then it might not have the script attached.
They aren't relative to your own local axes
(how would that work, anyway? your rotation determines which way your axes point!)
I prefer to deal with the actual angles as little as possible.
For example, to make an object rotate around a certain axis, I use Quaternion.AngleAxis
transform.rotation *= Quaternion.AngleAxis(90 * Time.deltaTime, Vector3.right);
in Update, this makes you spin around the world X axis at 90 degrees per second
This is what I'm trying to drag in. A script
Perhaps you are trying to reference a scene object from a prefab, as SPR2 just asked about
also, are you literally trying to drag a script asset in?
Yes?
this is a script asset, for exmaple
Oh no
this is a MonoScript. it's how the editor represents a script file
on the other hand, this is an instance of EllipsoidTest (attached to a game object)
Ooooooh wait, I'm trying to drag the player object in ๐คฆ๐ปโโ๏ธ
Okay, so you're not doing that
But it sounds like you are trying to drag in a scene object.
Can't do that for the reasons mentioned earlier
You'll have to pass it via the code upon instantiating it
if i split by string and that string is at the end of string do i get array of one or two
Two, unless the StringSplitOptions.RemoveEmptyEntries argument is passed to the method.
Im very new to unity and im following this tutorial https://www.youtube.com/watch?v=MDMNIGtbiz8&list=PLJ96i5RTnDvs6rrbDvRHVA3VyZGLnvIN9. But im trying to do it in 2D. In the tutorial theyre using raycasting but from what i have read that doesn't work on sprites / 2D stuff. How can you change this code: https://gdl.space/kobaworetu.cs so it works in 2D?
Unity has separate 3D and 2D physics systems.
in terms of physics unity has 2D version of everything in 3D
since they are seperate engines (Box2D vs Physx)
Physics does work on '2D stuff'. Basically what you must do is find ALL of the used physics API/s components and change them to their 2D equivalents
note that raycasts never work on sprites -- 2D raycasts hit 2D colliders.
any physics components suffix with "2D" then you need to use methods under Physics2D to work with them
If i add a Box collider to someting will the raycast still hit the Sprite and get no result?
box collider is a 3d collider
use the box2d
Physics2D.Raycast + Collider2D is all you need
again, raycasts will never hit a sprite renderer
a 3D raycast hits 3D colliders, and a 2D raycast hits 2D colliders
that's it.
okay ill try that
I think i explaind the wrong thing. How do i get a sprite to move to a 2D Box collider i clicked with my mouse?
[SerializeField] Transform theThing
theThing.position =
raycasthit.point or raycasthit.collider.transform.position
sprites themselves don't do any moving, its the Transform component that determines the position of your objects
rigidbody.AddForceAtPosition(force * variation * up, hit.point); rigidbody.AddForceAtPosition(force * variation * -transform.forward * 0.40f, hit.point);
How do I combine these into one
-transform.forward is pitch and up is roll
I want both of these
Vector3 up = -rigidbody.velocity.normalized;
Well you don't really need to but
Just add the vectors
Also typically a drag force would be applied in the opposite direction of motion
Aka -velocity
Wdym add the vectors
They both work wonderfully I just want them both lol
Its making my bomb like drop rotating around before stabilizing
Add.
+
Wait literally
But what you're doing right now adds them anyway
I don't understand what you're asking
You say you want both but you don't want both
Pick one
Not sure what you mean by overlapping too
Neither of these makes sense to me
One rotates on the z and one rotates on x
I want to rotate BOTH
If I add both of these lines to code only one works
You would want a force:
- applied at the tail
- in the direction opposite velocity (-velocity)
- proportional to the magnitude of the velocity
That's all
Idk
There's no reason you would need a separate force for each axis or something
Nah like
Not true, AddForce is additive
All forces will be applied
I just added them but it only rolls
Dont rotate to face down
Rolls as in spins on itself
Well like I said neither one makes sense.
The first one is using the rotation of the object, which doesn't matter
The second one is normalizing the velocity, which means it's not proportional to the velocity.
And for both you're applying them at "hit.point" which is... Where?
Is there a Raycast involved or something? Why?
Yeah
This is my recommendation and matches how real life works
I kinda ripped this code of the internet
And adjusted how it roles
This seems too complicated for me and the effects of this is quite amazing
Wait
I can just add constant spin force
Im too stupid for this lol ๐ญ
Quick question what does Vector3.Reflect exactly do
var rotation = rectTransform.rotation;
rotation = new(rotation.x, rotation.y, Random.Range(-90, 90), rotation.w);
rectTransform.rotation = rotation;
Debug.Log(rotation);
Debug.Log(rectTransform.rotation);
huh? Why are the values different
You're passing nonsensical values to a quaternion so it "fixes" it in the transform
Huh
you should probably use rectTransform.eulerAngles instead
I just want to change the z rotation
Yes, the z rotation of Euler angles. It's not the same as the z component of a quaternion
what makes you think this would work?
rotation = new(rotation.x, rotation.y, Random.Range(-90, 90), rotation.w);
please refer to the docs
https://docs.unity3d.com/ScriptReference/Vector3.Reflect.html
The docs tell you exactly what it does
OH right the docs sorry i forgot
Cheers this did the trick
var rotation = rectTransform.eulerAngles;
rotation = new(rotation.x, rotation.y, Random.Range(-90, 90));
rectTransform.eulerAngles = rotation;
This is not a good idea. You have no idea what x and y are and how changing z will affect the rotation
Now I want to predict where my bomb will land can anybody help? it uses an air resistance script that randomizes where it drops everytime
What do you mean? It works
but does it work if you call it twice?
I don't need to
well it will only work if your initial rotation is 0,0,0
Mmm, I just tested it and it still works even the second time
So I don't know what you mean haha
The quirks of Quaternion math. The Vector3 you put into a Quaternion will not be the same Vector3 when you read it again
Generally the rule of thumb is, you start work on a game on one LTS version on Unity and you stick with it unless something really important means an update is better than stability
The LTS will receive patch releases for much longer than other releases.
This means that you won't have to move to a different major version for a long time
to add on to that: LTS releases typically receive updates for about 2 years. tech stream versions only receive patches until the next version comes out. for example 2021.3 which is an LTS is still receiving patches, but 2023.2, the previous tech stream, is not
note that the LTS isn't necessarily less buggy than a non-LTS release.
mostly in the early life of the LTS
LTS means long term support. That's all.
Hello, I'm kinda new at game development. I have enemy spwaner in my game. I did manage to handle it, but enemies(slimes) doesn't go where my player current location. Instead they go player spawn location(middle of screen). I couldn't figure it out can you guys help me?
EnemySpawner code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random=UnityEngine.Random;
public class SlimeSpawner : MonoBehaviour
{
public GameObject Slime;
public float targetTime;
// Start is called before the first frame update
void Start()
{
}
void FixedUpdate()
{
targetTime -= Time.fixedDeltaTime;
}
// Update is called once per frame
void Update()
{
if (targetTime <= 0.0f)
{
TimerEnd();
}
if (targetTime < 0.0f)
{
TimerRestart();
}
}
void TimerEnd()
{
var position =new Vector2 (Random.Range(-5f, 5f), Random.Range(-5f, 5f));
Instantiate(Slime, position, Quaternion.identity);
}
void TimerRestart()
{
targetTime = 2;
}
}```
Slime Code(moment, die etc):
using System.Collections.Generic;
using System.Security.Cryptography;
using Unity.VisualScripting;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
public class Slime : MonoBehaviour
{
[SerializeField]
private GameObject player;
[SerializeField]
private float speed ;
private float distance;
public int health = 40;
public Animator anim;
[SerializeField]
private Collider2D Collider;
void Awake()
{
speed = Random.Range(0.1f, 1.5f);
}
public void takeDamage( int damage)
{
health -= damage;
if (health <= 0)
{
die();
}
}
void die()
{
Collider.enabled = false;
speed = 0;
Destroy(gameObject, 1.2f);
anim.SetBool("dead", true);
}
void Update()
{
move();
}
void move()
{
//check te distance between slime and player
distance = Vector2.Distance(transform.position, player.transform.position);
Vector2 direction = player.transform.position - transform.position;
transform.position = Vector2.MoveTowards(this.transform.position, player.transform.position, speed * Time.deltaTime);
}
}
Well you have no way of the slimes getting a reference to the player. The spawner should give the slime a reference to the player
you are referencing the player prefab right now
that has nothing to do with the instance of the player in the scene
give the slime spawner a field that can reference the player (the actual player in the scene)
Thanks! i'll try
The spawner can then pass that reference to the slimes it creates
well, yes, GetComponent only works for components
where does this data actually exist?
Wait, what?
its a class with json information in another script
You're talking about the class which code you've sent?
the info is what i want to get, the info is a class in another script
Well, it's an object
If you're trying to find an object with the tag
So there should be no problem in accessing its component
there must be a monobehaviour that uses that data, so that is the component you need to get
If the skin info is accessible from the GameLogic class, then you need to access it with that.
Like logic.SkinInfo taking your code as an example
this is the script
i chanfge it so it finds SkinInfo
but i need to get the info from SkinInf of the skin
So, GetComponent<SkinInfo>().info
I find it strange that there just isn't a boolean on transform components to disable rotational inheritance
Why do you even have 2 classes called the same, but with no last letter in the 2nd one?
Can't you come up with a more original name?
Like SkinData?
Do people usually just use the rotational constraint class and target some singleton in the scene? There's got to be a better way than that
Well, I have given you a really original example already
SkinInfo is a Component, as MonoBehaviour : Behaviour : Component : Object. SkinInf isn't.
just dont parent if you dont want the child to inherit the attributes of the parent
How would I make an arcade machine or a tv? Is it possible to render a 2d scene in another 3d scene or something to get that effect?
easiest way is a RenderTexture
sounds like a texture thing. I need an interactive 2d scene in a 3d one
But there's plenty of situations where you just need that positional inheritance, more so than the rotation.
you should really check before making assumptions. they are interactive because they show what a camera sees
Quick question I'm hoping someone can answer. If I use callback context events with the new input system to set variables like the following:
_playerControls.PlayerMovement.Movement.performed += i => _movementInput = i.ReadValue<Vector2>();
Does it make any sense to have any input assignments run in Update() as well? I've seen this done in a tutorial I was watching so I just want to double check in case I'm missing something. From my understanding of the flow of how Unity updates stuff the event inputs will run before Update() anyways so this would be redundant(?)
hello! im trying to make a TextMeshPro component animate counting from 0 to a value score during a 3 seconds period. can someone plz help me with this cuz i dont know how to do it
I prefer to read continuous things in Update, rather than responding to callbacks like that
but they'll be pretty much equivalent, yes
importantly, I'm not sure how this'll behave when the input goes back to zero
do you get one last performed callback, or is it a canceled callback?
says that Object reference is not set to an instance of an object (info.JsonEquipSkin)
what else am i supposed to reference except info
well, presumably, blueButton
since you're using that
oh, on the next line!
that means that Info is null
perhaps you have multiple instances of whatever this component is
and one of them is missing a reference
Well, the way the movement is set up is as pass through. I'm only using .performed and it's giving me values whenever there is change to the movement controls. So if it changes to 0 it'll do an event changing it to 0. For other actions like "jump" I am using .performed and .cancelled to set a boolean.
Hopefully that answers your question. I'm still pretty new to all of this so my understanding is limited.
I see. Thank you for your insight.
how do I fix this?
You need to actually provide some information to work with. And describe the issue with words
I assume you mean how the player jumps backwards? Then show the movement code
nevermind I fixed it >:)
๐ธ
do i need to switch the AnimatorControler or AnimatorOverrideControler. Im switching between them to change the skin of a 2d sprite
public RoomTile[][] TileSections { get; private set; }
How do I get the middle index of the second part of the array?
int middleIndex = TileSections [TileSections .Length - 1][???];
nvm I think I got it.
In a jagged array each nested part of the array can have a different length. but you shoud be using the .GetLength method
whats the advantage of using GetLength?
It doesn't apply to your use-case, as jagged arrays are only one dimension.
does anyone know why my variables dont save across scenes?
using System.Collections.Generic;
using UnityEngine;
public class RandomVariables : MonoBehaviour
{
public float Volume;
public float Fov;
public float Sens;
}
public class MouseLook : MonoBehaviour
{
public RandomVariables RV;
public AudioMixer VolumeMixer;
void Update()
{
PlayerLook();
Camera.fieldOfView = RV.Fov;
VolumeMixer.SetFloat("Volume", RV.Volume);
}
public void PlayerLook()
{
float mouseX = Input.GetAxis("Mouse X") * RV.Sens * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * RV.Sens * Time.deltaTime;
this is the only code that uses those Variables
You aren't doing anything that would make that happen
idk i tought itl just get stored
When you load a new scene, all the GameObjects in the old scene get destroyed
BTW your mouse look code is wrong, you should not be multiplying deltaTime into mouse input. It's already framerate independent
i mean it is working
It's easy for me. Harder for a beginner who doesn't understand things well
and it isnt the whole code
i mean how hard is it?
Working but it will be very weird and jittery
Very easy
like how many lines?
cause people say Adding a save function to ur game is easy but its like 800 lines of code
i just need 3 variables
Are UI elements kinda inefficient or is some specific setting on them that makes them that way? If I spawn in 2000 resource prefabs around the game world it has 0 effect on FPS but if I put a healthbar on them which is a canvas element with images the FPS completely tanks. Is the way to deal with this just enabling the healthbars close to the player or is there a way to make them more efficient?
canvas per healthbar is a meme if you are making tons
I was scrolling through options under Edit -> Project Settings (trying to find script execution order) and idk what I did, but all my text mesh pro broke and it somehow also broke my scene's lighting. Any clue as to what might have happened?
I didn't check any boxes or changed anything. Although I was using the Down key to select the next tab (in the project settings) so maybe it did something? Idk
https://www.stevestreeting.com/2019/02/22/enemy-health-bars-in-1-draw-call-in-unity/
Here's how I do it if you do want that performance
Recently I needed to do something pretty common in many top-down games: render a whole bunch of health bars for enemies on the screen. Something like this:
Obviously, I want to do this as efficiently as possible, preferably all in a single draw call. As I always do before I start something, I did a quick search online of what other people are do...
ty ill check it out
The material property block section is a built-in pipeline feature, so you can ignore that if you're using URP and set the fill directly. You want to make sure you object pool your enemies and units this way too because destroying materials do not cleanup so easily.
could this be the issue?
damn, idk how that got turned off, thanks
Did you install URP into this project after creating it?
i changed value in Cinemachine default input system how can i get it back ???
what do you mean?
cinemachine give a input provider and i modified the value of the input like it changed it to button instead of value in the input system then i didnt know how to revert it back and deleted it ......
and now i dont know how i can get the input back
just delete the cinemachine component and create it again surely? should work
It's just a reference to whatever input action you want
Put whatever actions you want there
but i dont know how it works
how what works
the input thing
idk the original inputs
yes ?? so it works
just reset the component, no?
doesnt work
like i know how to make a new input but i dont know which one where used
well you said you deleted it right
why did you do that
I presume you mean in the input action asset
Reimport the samples and check the input asset Id suggest
I didn't think there was a default one to be honest
So why not just ctrlZ a bunch
Otherwise just remake it
i dont even know i changed some value tried to revert it back and couldnt find the orignal input used for the mouse for i deleted it
ctyrl-z didnt work on input system :(
If you just want mouse input
just make a new action bound to the mouse
and use that
yes but i dont know what input iqs used for the mouse
it was written Den or something like that on the path thing
but i cant find it anywhere
Make an action:
Action Type: Value
Control Type: Vector2
Bind it to Mouse Delta
no idea what you mean by "Den"
it was Delta not Den
where do i find Delta ?????
Missed opportunity to actually learn what the scripts are doing you gonna use ๐
Follow these instructions
damn the only thing that was missing was Vector2.....
Please keep in mind that I'm a complete newbie to Unity and C#. Started ~4 days ago
Purpose of the script: I was attempting to make it so that if the player steers too far right (>70), or too far left (<-70), the camera wouldn't follow their movements. This was in order for the player's vehicle and the road to stay viewable, and not go off camera.
The Issue: Although the script works as intended when the player's vehicle rotates to the right (Y axis), it doesn't move at all when the vehicle rotates to the left, which is a major issue.
The Script:
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public Transform player;
public Vector3 offset;
void Update()
{
transform.position = player.position + offset;
if(player.rotation.eulerAngles.y < 90 && player.rotation.eulerAngles.y > -90){
transform.rotation = player.rotation * Quaternion.Euler(15, 0, 0);
}
}
}
Video showcasing the problem:
And yes, I know that 70 degrees is still not a good angle as the majority of the vehicle still gets offscreen, I will mess around and change that later on.
Extracting and comparing euler angles from a Transform is generally fraught with pitfalls. For one, euler angles are not unique, and you can't really glean much useful information just by looking at a single component in isolation.
It's much better to explicitly sample the angle of the object around a particular axis, rather than trying to glean such information from the euler angles.
One simple way in this case is to simply compare the angle of the player object's forward direction with the "expected" direction.
In this case you want to basically limit the amount your camera will roatate along with the player. I suggest this simpler approach:
// rotate a max of 70 degrees away from "forward"
float maxAngle = 70f;
// Rotate the same way as the player, up to the max
Quaternion camRotation = Quaternion.RotateTowards(Quaternion.identity, player.rotation, maxAngle);
transform.rotation = camRotation;```
Missing from your explanation here though is some context about what style of game this is, what the desired camera shot is, what kind of movement your player is limited to, etc..
all of which may modify the advice here..
Thank you! It works and functions exactly the way I wanted it to. I don't really know what the RotateTowards method is yet though so I am gonna have to look that up and understand how it works first.
(btw when sharing videos use mp4 as it willl embed in discord properly)
Imagine starting at rotation A and rotating towards rotation B until you either reach B or the maximum number of degrees.
Where you end is the result of the function
And the maximum number of degrees is the 3rd parameter?
what are some must doโs as a beginner in unity I just made my own version of flappy bird
No must-do's but:
Brickbreaker,
Battleship,
Roll a ball
2d and then 3d platformers
are these also youtube tutorials or should I try and wing it
I'm sure there are tutorials. I recommend, if you are going to use them, only use tutorials for inspiration, not to actually copy
!learn ๐
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
Yeah I didnโt do that, I need to do that more
It can be tough, but is very rewarding and you certainly learn better
That is a tough one haha. But a lot of fun. Best of luck!
hi guys questions about scriptable objects. Do I instantiate the scriptable object, or the prefab gameobject its going onto?
never mind im stupid
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collision : MonoBehaviour
{
void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("Ouch");
}
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log(other.tag) //returns Untagged
if (other.CompareTag("Package"))
{
Debug.Log("Picked Up");
}
}
}
`
i have just started coding in unity and i ran into this issue. i have tagged the game object as "Package" but unity keeps identifying it as Untagged for some reason? How do i fix this
Is the standard git workflow for a new project to create the git repo on the site, clone it to anywhere on your system, create the unity project somewhere else, close unity, move the unity project INTO the cloned repo folder, then push?
yoo beeftips can u help me out with my question?
I'm really new as well so I cant help you woth that, sorry. I can guess that the other param object doesnt have a tag assigned though if I had to guess
oh alright, thank you regardless. what's the param object? ive only started coding today
You are colliding with something else then. Log the name of the game object as well
but i only have one collider component
That is not how I do it, no
where it says OnTriggerEnter2D(Collider2D other), Collider2D other is your parameter object. Collider2D is its type and other is the name given used in the method. When the trigger happens on whatever this script is attached to it looks at the object it triggers on and see if it has a collider2d and passes that as the object there as an argument
Then how could you get the callback? It requires one on each colliding object
2 actually (counting the ridig body)
ohhh alright i see what you mean
yea i meant 2 including the rigid body as well
one is a trigger the other is a collider and and rigid body
How do you do it?
Git init my unity project folder and publish then push it
No need to move anything
i logged the name, it is colliding in the desired object
Show the inspector for that object
And the console with the logs
yeah thats what you have written "Debug.Log(other.tag)"
Collision is the script receiving the callback, right? So "other" is the other object involved in the collision. Whatever is NOT "person"
but like caw is not set on isTrigger
Irrelevant
OnTriggerEnter is sent to both objects involved in the collision
ohhh
The one you have the script attached to is NOT ever "other"
The parameter you receive is the other object, because it of course has access to itself already
ohh alright so what parameter do i use for person?
Nothing
it of course has access to itself already
The script is attached to person, why even check if it is person.
Of course it is, that won't change
how would this code change if i need it to recognise the tag on person instead of "other"
There would never be a reason to do that
The script is ON person.
You can check your own objects tag I guess though. gameObject.CompareTag
Look up 'CompareTag'
They are already using that. The issue is that they thought the parameter they received was the object the script was attached to
"other" is just a name, a decent one letting you know that "other" is the other object entering in the triggers area. It can be literally anything with a Collider2D
Did you perhaps want to have this script on Caw, and then check if it collided with player?
i have 2 sprites. i need caw to collide with both of them. they have different tags. when it collides with one it should recognise which tag was on the object it collided with
Otherwise, you should be checking if you hit caw...
ohhh right
okay
the tutorial i was following did not put it on caw
but yeah if you wanna check if that thing is a person like youre intending to do something to it then do what you did with "Package" there but for "Person" if person has an assigned tag of "Person", or whatever other tagname you give it
but i see it now
Did it check if the other object was caw?
Otherwise, that is a bad tutorial
no it was checking what caw collided with
Oh, so then the script must have been on caw
i paid 50$ for it ๐ญ
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
yea its working now!
i did indeed
That's 750 hours for free, and it is better than pretty much anything else out there
gyatdamn
There is no reason to ever pay for lessons except in a university (for computer science, not game dev)
thank u sm for this i can still refund the course
its only been 12 hours
Nice
If you want to dive a bit deeper, you can also ignore certain collision with physics layers. If it makes sense in your game ( https://docs.unity3d.com/Manual/LayerBasedCollision.html)
Something that is not necessary in this situation, but good to know about ๐
i will look into this, thank you so much!
I saw this on some devlog just now. Where can I access this?