#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 357 of 1

late burrow
#

assuming noone actually loads them by accident

#

whatever can we go back to original question

#

best way to compress samples to minimize disk usage

slender nymph
#

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

late burrow
#

i love others searching for excuses to kick me out of discussion

frosty hound
#

@late burrow Be quiet please. If you have more nonense to kick up, make a thread as always.

polar acorn
#

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

chrome valve
#

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?

rich adder
chrome valve
#

@rich adder as you can see, it doesnt offer me 2d vector

#

but, the tutorial does, you knomw?

rich adder
chrome valve
#

theirs has "add vector2d composite"

chrome valve
rich adder
#

yes a Button would not have a composite

#

a button cannot be a composite

chrome valve
#

๐Ÿ˜ฎ

#

wait, what should it be isntead

rich adder
#

somehting like value

#

then choose vector2

chrome valve
dusty ridge
#

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;
        }
    }
}
polar acorn
wintry quarry
polar acorn
#

It does not matter where the mosue is

dusty ridge
#

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?

polar acorn
dusty ridge
#

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

verbal dome
#

What line throws the null exception?

dusty ridge
#

yeah not being referenced in anyother script

#

that same line lol

wintry quarry
polar acorn
dusty ridge
#

73

polar acorn
dusty ridge
#

OK your pinting out something but what?

polar acorn
eternal falconBOT
summer stump
dusty ridge
#

ok so how I do I paste it here then

verbal dome
#

Doesnt even have 73 lines

dusty ridge
#

nvm I going to the forums

errant pilot
#

Guys the child part is correct but it isnt working where did i go wrong?

summer stump
polar acorn
dusty ridge
#

yeah now you see teh problem lol

#

lol

verbal dome
#

Pretty sure you can just use transform.position instead of transform.GetComponent<RectTransform>().position btw.

verbal dome
#

That's the issue

polar acorn
dusty ridge
#

neither work all cards reset no matter what all go to parents position o matter what with Horizontal Layout Group

dusty ridge
#

I gave the orrect info lol not my fault the engine is buggy af

polar acorn
#

You still refuse to tell us what line your error is on

dusty ridge
#

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.

polar acorn
#

I can't help someone who hasn't developed object permanence yet

frosty hound
#

@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.

polar acorn
#

You are aware that we cannot see your goddamn screen right

wintry quarry
frosty hound
#

!mute 436401905392943105 1d You can return tomorrow. If the forums haven't helped solved your issue, you can ask again here with proper details.

eternal falconBOT
#

dynoSuccess mouse8763 was muted.

polar acorn
#

"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?"

fresh osprey
#

oops

frosty hound
#

It truly is baffling to think people actually communicate that poorly

fresh osprey
#

oh he did

languid spire
frosty hound
eternal falconBOT
fresh osprey
#

oop you spammed it in the process but yeah

#

my discord was lagging so they all appeared at once on my screen.

fresh osprey
frosty hound
fresh osprey
#

oh, its fine if its not you. but its not a discord issue. ive never been warned by any bot this many times

fickle plume
fresh osprey
#

Yeah. I have. I explained it was an issue. Didnt need to get revenge on me by spamming me back though, okay?

fickle plume
#

Like I said, I was catching up from another channel you've spammed in

fresh osprey
#

@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?

slender nymph
#

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

fresh osprey
#

every time trust me

slender nymph
#

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

summer stump
#

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

swift crag
#

Volume casts are slower, yes, but it's not going to matter here at all

wintry quarry
#

sure it would be like carrying 2 drops of water in your gallon bucket instead of 1

swift crag
#

(and they're not that much slower, from my experience)

polar acorn
#

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

swift crag
#

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)

stuck palm
#
public override void OnPointerDown(PointerEventData eventData)
    {
        audioSource.PlayOneShot(click);
        OnClick();
    }

why isnt the code in here running?

#

im using a controller to navigate

wintry quarry
#

also if you're using a controller that meanw there's no pointer down

#

pointers are mice and touchscreens

stuck palm
wintry quarry
#

or override OnSelected

wintry quarry
# stuck palm im using the selectable class

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

stuck palm
stuck palm
wintry quarry
#

I know I'm telling you a cleaner way to do the same thing

stuck palm
#

oh right

#

selected is highlighted though, isnt it?

swift crag
#

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)

stuck palm
wintry quarry
#

just selection

stuck palm
#

isnt the interface for clicking ipointerclickhandler?

wintry quarry
#

You want ISubmitHandler / OnSubmit

stuck palm
#

SUBMIT thats what it was

#

thank you

bright violet
#

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?

slender nymph
#

try regenerating project files

stuck palm
#

what is null here?

slender nymph
#

do you have an event system active in the scene?

slender nymph
#

that just shows you have a GameObject named EventSystem. look at its components to make sure it actually has the EventSystem component on it

bright violet
slender nymph
#

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

stuck palm
slender nymph
#

and this object is already in the scene before the PlayButton's OnEnable method is run?

bright violet
stuck palm
slender nymph
#

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

slender nymph
#

is this happening after loading from a different scene or is this the first scene you load?

slender nymph
#

then i'd suggest using the debugger to step through the code and figure out why EventSystem.current is returning null

slender nymph
stuck palm
#

thanks

stuck palm
willow scroll
#

You do fix it

stuck palm
willow scroll
#

You probably don't have an EventSystem

dusty silo
#

I would like help with this still. The system will detect Vertices, but not edges other than their colliders being nearly identical.

ember tangle
#

Is it okay to have an Interface without MonoBehaviour inheritance contain member objects that are MonoBehaviours?

timber tide
#

wat

swift crag
#

well, an interface doesn't have fields..

#

but any code can work with MonoBehaviour-derived classes, sure

real falcon
#

do you guys know what this means

#

I am getting this after I updated my Unity version

rocky canyon
#

loooks like an editor error /bug

#

restart unity and see if it still appears

real falcon
#

I did, it still appears

#

what about this camera one

wintry quarry
#

Something is weird with your camera object

rocky canyon
#

^ ya thats a new one

real falcon
#

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

rich adder
rocky canyon
#

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
swift crag
#

I've seen the editor have a little hiccup and screw up the additional camera data before

rich adder
swift crag
#

i think i saw that happen to the scene camera once...

#

which is spooky

rocky canyon
rocky canyon
#

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

real falcon
#

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

rocky canyon
#

ya, in URP u can use Renderer features to fix that issue

#

its not the same workflow as the 2 camera setup

swift crag
#

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

rich adder
rocky canyon
#

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...

โ–ถ Play video
rich adder
#

yup this one helped me ^

swift crag
#

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

rocky canyon
real falcon
#

ill try it

rocky canyon
#

still relevant.. but with URP u can save soem performance by not having an extra camera

rich adder
#

renderer features in URP are dope

rocky canyon
#

and like navarone mentioned.. u'd get better shadows as well

rich adder
#

you can make easy outlines , see through walls objects etc

rocky canyon
#

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

rich adder
#

yeah the rendering order and passes

rocky canyon
#

yes, this ^

#

i already had it working but i dont like to lean on systems i dont understand too much

rich adder
#

iirc if you look at the frame debugger you can see what happens on each pass

rocky canyon
#

like the depth

#

frame debugger is correct ๐Ÿ‘

rich adder
#

I've been trying to play with renderer feature to get an easy "obra dinn" look

rocky canyon
swift crag
#

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

rich adder
swift crag
#

but the frame debugger showed the expected identity matrix

rocky canyon
#

yea this one is sus.. not sure what its viewing from

swift crag
#

the sun, perhaps

rocky canyon
rocky canyon
stuck palm
#

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?

summer stump
#

What is the error?

stuck palm
polar acorn
lethal swallow
#

Sorry, why does the enemy phase into the ground when attacked?

#

tysm

slender nymph
#

doesn't look like a code issue. looks like you are using a non-humanoid animation on your humanoid rig

lethal swallow
#

sry for wasting your time

#

also, it is a free asset from the asset store

slender nymph
#

have you tried looking at the settings for the animation?

lethal swallow
#

this?

slender nymph
lethal swallow
#

these?

slender nymph
#

try looking at the animation clips that the warning in that screenshot is telling you about

lethal swallow
#

sry 1 sec wrong image

slender nymph
#

because that is still the animation component and not the animations themselves

lethal swallow
astral falcon
#

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

eternal falconBOT
hallow siren
ember tangle
#

What is the best way to delete a GameObject after calling exampleGameObjectsQueue.Dequeue()

slender nymph
#

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

ember tangle
#

Maybe I misunderstand but I thought I lose the pointer once I use Dequeue()

swift crag
#

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

ember tangle
#

Hmm maybe

// do stuff
Destroy(foo);``` ?
slender nymph
#

yes

ember tangle
#

alright thanks

summer stump
slender nymph
#
  1. that is backwards
  2. why, they never gave any indication of wanting to delay the destroy
lapis yew
# rocky canyon
  1. recalculate UV's in blender
  2. warped faces that bend/overlap
frosty hound
#

Please don't post incorrect answers

lapis yew
#

ive seen this before in blender (and unity alike)

ember tangle
#

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.

glossy turtle
ember tangle
#

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?

glossy turtle
#

That was a basic about movement and rotation.

rocky canyon
ember tangle
summer stump
strong sorrel
#

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;

rocky canyon
#

i usually use PascalCase for all public variables regardless if their static or not

#

camalCase for private.. and an _forLocalVars

strong sorrel
#

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

rocky canyon
#

really up to you tho, as long as its consistent

strong sorrel
#

funny how it makes it clearer

rocky canyon
#

well, its like color coding a file-cabinet ๐Ÿ˜„
once u file enough Due-Bills in an orange folder..
orange starts to give you anxiety

mint dove
#

you can name ur variables whatever you want if it's clear and easy to read

strong sorrel
#

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

rocky canyon
#

i do see captial statics alot

#

GRAVITY for example

strong sorrel
#

thats what you do in java i know that

rocky canyon
#

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#

devout swift
#

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.

mint dove
#

ctrl shift p

rocky canyon
#

Ctrl + Shft + P

slender nymph
rocky canyon
#

Cmd if ur trendy

devout swift
rocky canyon
#

means when a console error appears.. it auto-pauses

mint dove
#

error pause

rocky canyon
slender nymph
#

pro tip: leave it on and fix your errors

devout swift
#

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.

glossy turtle
rocky canyon
#

if you leave it off remember to fix ur errors before u build

slender nymph
rocky canyon
#

but moooom....

devout swift
#

and I don't know what that is.

rocky canyon
#

its some Mobile/ Android error

tame mist
#

if i want to put a script in here to reference from how should i do so? like with codepen?

rocky canyon
#

!code

eternal falconBOT
tame mist
#

thank you

devout swift
#

So does that error pause acts on what? Red errors only or it can also react on yellow errors??

slender nymph
#

the yellow ones are warnings, not errors

rocky canyon
#

Red are actual errors.. yellow is warnings and white is just logs

#

red are bad

#

Red will break ur game.. hence why it pauses

devout swift
#

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.

rocky canyon
#

seems u can bypass that error while u work w/o ur phone connected

devout swift
#

Anyway thank you guys. That was stressful lol.

tame mist
#

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

static cedar
#

I know this is annoying but the Transform.position is global.

#

You're probably looking for Transform.localPosition.

cosmic dagger
tame mist
static cedar
cosmic dagger
static cedar
cosmic dagger
#

position from the inspector is the local position, not the global position . . .

static cedar
#

I also think i'm a bit too sensitive when it comes to tiny things, so it could just be me. UnityChanPanicWork

rich adder
static cedar
#

Hmm i guess it's up to interpretation. UnityChanThink

rich adder
#

I always used them that way ๐Ÿคทโ€โ™‚๏ธ

cosmic dagger
static cedar
#

Context wise, it feels like sighing against the obvious.

#

That's how i see it from months ago being here. UnityChanThink

cosmic dagger
#

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) . . .

glossy turtle
static cedar
tame mist
static cedar
#

And so on.

cosmic dagger
tame mist
#

oh boy ๐Ÿ™ƒ

static cedar
tame mist
#

lol

static cedar
#

Didn't structure the game object well.

tame mist
#

yeah i'm fairly new

#

this will be a good lesson i guess

cosmic dagger
#

any one of these that arent at 0, 0, 0 will offset all of their childrens' positions . . .

static cedar
#

Understandable. I've rewrote something as much as 4 times.

eternal needle
cosmic dagger
#

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 . . .

rocky canyon
#

controller height is the entire capsule.. from the bottom to the top..

radiant frigate
#

hi! is there a way to scale gameobject on instantiate? looked at api docs and couldnt find it

slender nymph
#

Instantiate returns a reference to the created object, just use that reference to modify its transform.localScale

radiant frigate
slender nymph
#

the "reference" i was referring to what the object returned by Instantiate

#

your prefab is irrelevant

radiant frigate
#

by reference you mean the object it creates?

#

"instantiates"

slender nymph
#

Instantiate returns a reference to the created object

eternal falconBOT
radiant frigate
#

oops

#

mb i didnt want to ping you

#

even though i was meant to paste code

#

do you mean something like this?

summer stump
radiant frigate
#

isnt that what i want?

summer stump
#

I am just explaining what the code you wrote does

radiant frigate
#

okay

#

even though i still have to solve some unwanted mechanichs i think it is exactly what i need

radiant frigate
#

how can i set a script variable to get a component(the script) from an object thats neither the parent or child?

radiant frigate
#

ty!

#

i wasnt quite sure if that also counted as a reference but it made sense

summer stump
#

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

radiant frigate
#

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

summer stump
radiant frigate
#

it wont let me do that

summer stump
#

That is called "serialized references" in that link

#

Ah, is it to a prefab?
Prefabs can't reference scene objects

radiant frigate
#

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

radiant frigate
summer stump
# radiant frigate

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

summer stump
radiant frigate
slender nymph
#

also you can pop out the properties for a component from the context menu or you can lock your inspector

summer stump
radiant frigate
#

ty all!

radiant frigate
#

well my first language at all

#

and same with software

summer stump
#

Like the operating system itself

#

Like dragging a file into a folder

polar acorn
#

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

summer stump
#

I can't tell if this is super obscure joke or mistake
I kinda love it either way

radiant frigate
slender nymph
#

just drag the gameobject

#

it will get the correct component when you do

tacit estuary
# radiant frigate

You can also drag the spawner game object, and will auto grab the component

radiant frigate
#

ohhhhh

summer stump
#

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

radiant frigate
#

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

radiant frigate
#

np at all it was me doing weird stuff to check if it was working

plain jetty
#

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

lavish magnet
#

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?

cinder mason
#

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.

misty coral
#

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

hasty sleet
#

public void AddExplosionForce(float explosionForce, Vector3 explosionPosition, float explosionRadius, float upwardsModifier = 0.0f, ForceMode mode = ForceMode.Force));

solemn fractal
#

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 ?

hasty sleet
# solemn fractal Hey guys if I have a player class should I also put everything about the player ...

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.

solemn fractal
#

hmm ok, got it, thank you!!

hallow sun
summer stump
#

Never tried it though. Worth a shot ๐Ÿคทโ€โ™‚๏ธ

sour fulcrum
summer stump
sour fulcrum
#

same kinda vibe as Prefab's being kinda a single thing that's both an asset and an instance of said asset

summer stump
#

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

sour fulcrum
#

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

summer stump
#

Ok, I get what you mean. All just part of how reference types work

sour fulcrum
#

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

teal viper
#

Everything is an instance of some type

sour fulcrum
#

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

teal viper
#

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.

sour fulcrum
hallow sun
#

The same page gives you a different line that does get assets: FindObjectsOfTypeAll

sour fulcrum
teal viper
summer stump
teal viper
sour fulcrum
#

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

teal viper
#

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.

sour fulcrum
#

yeeee. annoying for freaks like me who make them at runtime

teal viper
#

Well, I don't see why you'd need that anyway

#

It's considered a not very great practice to instantiate SOs at runtime.

sour fulcrum
#

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

timber tide
#

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.

sour fulcrum
#

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

timber tide
#

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

sour fulcrum
timber tide
#

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)

ruby ember
timber tide
onyx tusk
#

how 2 make some action to happen when catched any exception at any code location & send 2 this action exception text?

final yoke
#

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

burnt vapor
#

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.

onyx tusk
burnt vapor
#

You can also cast to specific exceptions if you want to look for something specific

onyx tusk
burnt vapor
#

If it doesn't work then Unity broke it and you can't use it sadly

#

Which seems to be the case here

onyx tusk
#

ok, so what can i use?

willow scroll
#

Now I have mentioned that inline code block's appearance has changed

solemn fractal
#

hey guys is Singleton Pattern a good way to go with my scripts?

keen dew
#

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

tame cypress
#

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!

languid spire
tame cypress
#

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?

burnt vapor
#

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.

spiral narwhal
#

What's the purpose of direction in a circle cast

#

Isn't it just a circle with the given radius from the given point

slender nymph
#

the direction the circle is cast

slender nymph
spiral narwhal
#

I had expected something like this

honest haven
#

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

spiral narwhal
#

Where we just have an origin and a radius

slender nymph
#

again, that is an overlapcircle.

spiral narwhal
#

Ohhh it's its own thing

#

I see what you mean

gusty remnant
honest haven
#

cool thanks

wicked flare
#

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 ?

cosmic dagger
#

!code

eternal falconBOT
slender nymph
#

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 ๐Ÿ‘‡

eternal falconBOT
wicked flare
slender nymph
#

yeah you're meant to actually share the link, not paste it into a site then screenshot it

wicked flare
#

my mistake chief im new in this boat

slender nymph
#

also what did you even try? this code isn't even going to move the object at all because speed is never assigned to

wicked flare
#

wdym they move fine

#

oh wait

slender nymph
#

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

wicked flare
#

fuck nevermind i fucked up my code

#

yea you are right they dont move XD

wicked flare
#

ok solved that issue, how about the speed up?

#

i asked chat gpt but it wouldnt go as smooth as intented

slender nymph
#

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

wicked flare
#

no, not how fast they spawn, it just how fast they move gimme a sec and ill repost it

slender nymph
#

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"

wicked flare
wicked flare
#

so the speed increase rate is at 0.1 and initial speed at 5 and thats what im getting from currentSpeed

slender nymph
#

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

wicked flare
#

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

slender nymph
#

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

wicked flare
slender nymph
#

let me guess, this whole time you wanted them all to be the same speed and increase all at the same time?

wicked flare
#

yes ๐Ÿ™‚

slender nymph
#

then say that. because you gave no indication that was the end goal

wicked flare
#

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

slender nymph
#

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

wicked flare
#

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

fierce geode
#

Anyone have a good video on understanding Quaternions?

buoyant schooner
#

How would I be able to store specific data on a tile in unity?

wintry quarry
fierce geode
#

Underlying math, just to be safe.

rich egret
wintry quarry
#

There's no safety in understanding the math

burnt vapor
fierce geode
#

there is no safety in understanding quaternions

wintry quarry
rich egret
rich egret
#

OnRoomListUpdate

burnt vapor
rich egret
burnt vapor
#

I don't see anything calling this function

rich egret
burnt vapor
#

But you should not be able to assign a button to this considering the method takes parameters

wintry quarry
#

Show how you set that up

burnt vapor
#

Please show the button then

wintry quarry
#

Looks like a Pun behavior override

#

When do the docs say it should run

burnt vapor
#

Ugh

#

Well, never used that so idk then ๐Ÿคทโ€โ™‚๏ธ

fierce geode
#

Also is there any reason for why Unity Editor shows different values for rotations and not just euler angles?

rich egret
#

As you can see, the function does not appear there

burnt vapor
#

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

wintry quarry
burnt vapor
#

You can't assign it because your method must not take parameters

rich egret
burnt vapor
#

You don't pass parameterssssss

rich egret
#

okkkkkkkkkkkkkkkkk

burnt vapor
#

How is it supposed to know those?

#

Instead get the list in the method instead

#

Some things do accept parameters but not this one

short hazel
#

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

wintry quarry
#

Absolutely ^

fierce geode
#

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 ๐Ÿ’€

short hazel
wintry quarry
west sonnet
#

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'

analog thorn
#

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?

short hazel
west sonnet
short hazel
#

You cannot reference things from scenes into prefabs because there is no certainty that the prefab will exist in said scene.

swift crag
short hazel
swift crag
#

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

west sonnet
swift crag
#

also, are you literally trying to drag a script asset in?

swift crag
#

this is a script asset, for exmaple

west sonnet
#

Oh no

swift crag
#

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)

west sonnet
#

Ooooooh wait, I'm trying to drag the player object in ๐Ÿคฆ๐Ÿปโ€โ™‚๏ธ

swift crag
swift crag
west sonnet
#

Yeah

#

I am

short hazel
#

Can't do that for the reasons mentioned earlier

#

You'll have to pass it via the code upon instantiating it

swift crag
#

super common situation

late burrow
#

if i split by string and that string is at the end of string do i get array of one or two

short hazel
#

Two, unless the StringSplitOptions.RemoveEmptyEntries argument is passed to the method.

raven zenith
swift crag
#

Unity has separate 3D and 2D physics systems.

rich adder
#

since they are seperate engines (Box2D vs Physx)

languid spire
#

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

swift crag
#

note that raycasts never work on sprites -- 2D raycasts hit 2D colliders.

gaunt ice
#

any physics components suffix with "2D" then you need to use methods under Physics2D to work with them

raven zenith
#

If i add a Box collider to someting will the raycast still hit the Sprite and get no result?

rich adder
#

box collider is a 3d collider

#

use the box2d

#

Physics2D.Raycast + Collider2D is all you need

swift crag
#

a 3D raycast hits 3D colliders, and a 2D raycast hits 2D colliders

#

that's it.

raven zenith
#

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?

rich adder
#

sprites themselves don't do any moving, its the Transform component that determines the position of your objects

random cave
#

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;

wintry quarry
#

Just add the vectors

#

Also typically a drag force would be applied in the opposite direction of motion

#

Aka -velocity

random cave
#

Wdym add the vectors

#

They both work wonderfully I just want them both lol

#

Its making my bomb like drop rotating around before stabilizing

wintry quarry
random cave
#

Wait literally

wintry quarry
#

But what you're doing right now adds them anyway

random cave
#

Nah I cant have both

#

One overlaps the other

wintry quarry
#

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

random cave
#

oK SO

#

If I // the *up one

#

The bomb drops, rotates to face straight down

wintry quarry
#

Neither of these makes sense to me

random cave
#

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

wintry quarry
#

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

random cave
#

Idk

wintry quarry
#

There's no reason you would need a separate force for each axis or something

random cave
#

Nah like

wintry quarry
#

All forces will be applied

random cave
#

I just added them but it only rolls

#

Dont rotate to face down

#

Rolls as in spins on itself

wintry quarry
#

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?

random cave
#

Yeah

wintry quarry
random cave
#

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 ๐Ÿ˜ญ

random cave
spiral narwhal
#
            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

keen dew
#

You're passing nonsensical values to a quaternion so it "fixes" it in the transform

spiral narwhal
#

Huh

keen dew
#

you should probably use rectTransform.eulerAngles instead

spiral narwhal
#

I just want to change the z rotation

keen dew
#

Yes, the z rotation of Euler angles. It's not the same as the z component of a quaternion

languid spire
random cave
#

OH right the docs sorry i forgot

spiral narwhal
languid spire
random cave
#

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

languid spire
#

but does it work if you call it twice?

spiral narwhal
#

I don't need to

languid spire
#

well it will only work if your initial rotation is 0,0,0

spiral narwhal
#

Mmm, I just tested it and it still works even the second time

#

So I don't know what you mean haha

languid spire
#

The quirks of Quaternion math. The Vector3 you put into a Quaternion will not be the same Vector3 when you read it again

spiral narwhal
#

The randomness isn't too bad, quite the contrary

languid spire
#

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

swift crag
#

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

slender nymph
#

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

swift crag
#

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.

velvet sierra
#

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);

        
    }

}
wintry quarry
velvet sierra
#

Like GetComponent?

#

in the spawner script for player?

swift crag
#

no, you should just assign the reference in the inspector

velvet sierra
swift crag
#

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)

velvet sierra
#

Thanks! i'll try

swift crag
#

The spawner can then pass that reference to the slimes it creates

glad rune
#

it doesnt get the info because its not a monobehaviour

#

what do

#

its a class

#

json

swift crag
#

well, yes, GetComponent only works for components

#

where does this data actually exist?

glad rune
#

in another script

#

and i did put the script on a componet with the tag

willow scroll
glad rune
#

its a class with json information in another script

willow scroll
#

You're talking about the class which code you've sent?

glad rune
#

the info is what i want to get, the info is a class in another script

willow scroll
#

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

languid spire
short hazel
#

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

glad rune
#

this is the script

#

i chanfge it so it finds SkinInfo

#

but i need to get the info from SkinInf of the skin

languid spire
timber tide
#

I find it strange that there just isn't a boolean on transform components to disable rotational inheritance

willow scroll
# glad rune

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?

glad rune
#

no

#

im not original

timber tide
#

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

willow scroll
#

SkinInfo is a Component, as MonoBehaviour : Behaviour : Component : Object. SkinInf isn't.

languid spire
magic panther
#

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?

languid spire
magic panther
#

sounds like a texture thing. I need an interactive 2d scene in a 3d one

timber tide
languid spire
rotund forum
#

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(?)

sullen zealot
#

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

swift crag
#

but they'll be pretty much equivalent, yes

swift crag
#

do you get one last performed callback, or is it a canceled callback?

glad rune
#

says that Object reference is not set to an instance of an object (info.JsonEquipSkin)

#

what else am i supposed to reference except info

swift crag
#

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

rotund forum
# swift crag importantly, I'm not sure how this'll behave when the input goes back to zero

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.

rotund forum
hollow dawn
summer stump
# hollow dawn 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

rotund forum
#

๐Ÿ“ธ

glad rune
#

do i need to switch the AnimatorControler or AnimatorOverrideControler. Im switching between them to change the skin of a 2d sprite

abstract finch
#

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.

languid spire
abstract finch
zenith cypress
#

It doesn't apply to your use-case, as jagged arrays are only one dimension.

strong wren
#

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

wintry quarry
strong wren
wintry quarry
#

When you load a new scene, all the GameObjects in the old scene get destroyed

strong wren
#

oh

#

how can i save it?

#

pls dont tell me its hard

wintry quarry
wintry quarry
strong wren
#

and it isnt the whole code

wintry quarry
wintry quarry
strong wren
#

like how many lines?

#

cause people say Adding a save function to ur game is easy but its like 800 lines of code

wintry quarry
#

I don't know how to answer that

#

It depends on your game

strong wren
#

i just need 3 variables

timber tide
#

won't save session data though but you can carry your mono across scenes with this

noble leaf
#

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?

timber tide
#

canvas per healthbar is a meme if you are making tons

eager wolf
#

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

timber tide
# noble leaf Are UI elements kinda inefficient or is some specific setting on them that makes...
noble leaf
#

ty ill check it out

timber tide
# noble leaf 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.

eager wolf
#

damn, idk how that got turned off, thanks

swift crag
#

Did you install URP into this project after creating it?

sterile plover
#

i changed value in Cinemachine default input system how can i get it back ???

sterile plover
# wintry quarry 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

deft grail
wintry quarry
#

Put whatever actions you want there

sterile plover
wintry quarry
#

how what works

sterile plover
#

the input thing

sterile plover
wintry quarry
#

Does it matter

#

Make whatever you want

sterile plover
#

yes ?? so it works

wintry quarry
#

just reset the component, no?

sterile plover
#

like i know how to make a new input but i dont know which one where used

wintry quarry
#

well you said you deleted it right

#

why did you do that

#

I presume you mean in the input action asset

astral falcon
#

Reimport the samples and check the input asset Id suggest

wintry quarry
#

I didn't think there was a default one to be honest

#

So why not just ctrlZ a bunch

#

Otherwise just remake it

sterile plover
#

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

sterile plover
wintry quarry
#

If you just want mouse input

#

just make a new action bound to the mouse

#

and use that

sterile plover
#

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

wintry quarry
#

no idea what you mean by "Den"

sterile plover
#

where do i find Delta ?????

astral falcon
#

Missed opportunity to actually learn what the scripts are doing you gonna use ๐Ÿ˜‰

wintry quarry
sterile plover
#

damn the only thing that was missing was Vector2.....

ashen badge
#

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.

wintry quarry
# ashen badge *Please keep in mind that I'm a complete newbie to Unity and C#. Started ~4 days...

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..

ashen badge
wintry quarry
#

(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

ashen badge
#

And the maximum number of degrees is the 3rd parameter?

finite hornet
#

what are some must doโ€™s as a beginner in unity I just made my own version of flappy bird

summer stump
tepid swan
#

I have no idea how to use unity

#

Iโ€™ve had it for 2 years but never learned it

finite hornet
summer stump
summer stump
eternal falconBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

finite hornet
summer stump
#

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!

unkempt carbon
#

hi guys questions about scriptable objects. Do I instantiate the scriptable object, or the prefab gameobject its going onto?

short marsh
#

`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

cunning narwhal
#

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?

short marsh
#

yoo beeftips can u help me out with my question?

cunning narwhal
#

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

short marsh
#

oh alright, thank you regardless. what's the param object? ive only started coding today

summer stump
short marsh
#

but i only have one collider component

cunning narwhal
#

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

summer stump
short marsh
#

2 actually (counting the ridig body)

short marsh
short marsh
#

one is a trigger the other is a collider and and rigid body

cunning narwhal
summer stump
#

No need to move anything

short marsh
summer stump
#

And the console with the logs

short marsh
summer stump
#

Inspector for the object you want to be colliding with.

#

I guess "caw"?

short marsh
#

no caw is the rigid body

#

wait

#

oh so its reading caw's tag?

cunning narwhal
#

yeah thats what you have written "Debug.Log(other.tag)"

summer stump
short marsh
summer stump
#

Caw is untagged

#

There ya go ๐Ÿคทโ€โ™‚๏ธ

short marsh
#

but like caw is not set on isTrigger

summer stump
#

OnTriggerEnter is sent to both objects involved in the collision

short marsh
#

ohhh

summer stump
#

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

short marsh
#

ohh alright so what parameter do i use for person?

summer stump
#

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

short marsh
summer stump
#

The script is ON person.

#

You can check your own objects tag I guess though. gameObject.CompareTag

analog dove
#

Look up 'CompareTag'

summer stump
cunning narwhal
short marsh
#

i get it now

#

sort of

summer stump
#

Did you perhaps want to have this script on Caw, and then check if it collided with player?

short marsh
summer stump
#

Otherwise, you should be checking if you hit caw...

short marsh
#

okay

#

the tutorial i was following did not put it on caw

cunning narwhal
#

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

short marsh
#

but i see it now

summer stump
short marsh
#

no it was checking what caw collided with

summer stump
short marsh
#

i paid 50$ for it ๐Ÿ˜ญ

summer stump
#

!learn

eternal falconBOT
#

:teacher: Unity Learn โ†—

Over 750 hours of free live and on-demand learning content for all levels of experience!

short marsh
short marsh
summer stump
#

That's 750 hours for free, and it is better than pretty much anything else out there

summer stump
#

There is no reason to ever pay for lessons except in a university (for computer science, not game dev)

short marsh
#

its only been 12 hours

summer stump
#

Nice

short marsh
#

thank u again uve been very helpful!!!

#

means a lot to me

analog dove
short marsh
#

i will look into this, thank you so much!

magic panther
#

I saw this on some devlog just now. Where can I access this?