#💻┃code-beginner

1 messages · Page 516 of 1

dawn mulch
#

Ohhh I see. Gotcha. Okay well I'll cut the chatter then. I hope you have a good day and thank you all for taking the time to answer a couple questions.

rich adder
#

good'ay

dawn mulch
rich adder
rich adder
#

you should instead just capture the inputs inside a GetAxis

#

idk if that will fix it but worth a shot

#

movement = new (Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized;

#

thats weird.. maybe its your keyboard? never had issues with this code

#

Debug.Log the inputs and see whats happening

polar acorn
#

Show the updated code

rich adder
#

do you have arrow keys on your keyboard? try those

polar acorn
#

So, this is working in all directions individually, but doesn't work at all with up-right or down-right?

rich adder
#

that is strange

polar acorn
#

If it's working with your arrow keys, but doing this for WASD, then the problem is definitely your keyboard

#

Cheap keyboards can only detect a certain amount of inputs per "circuit" and if they've wired multiple keys to the same circuit it won't detect multiple presses

rich adder
#

have you actually debugged the values?

white obsidian
#

what could be the issue of my header not showing up in unity? the Patrol points and movement parameters headers are showing but Enemy isn't

short hazel
white obsidian
#

oh damn

#

really

#

😄

#

sorry for the stupid question.. : D

jaunty coyote
#

im absolutly confused, using the new navigation system of unity my ai cant follow the player. I put agent.SetDestination into update function and the ai just stops and stays in place because it only get partial state paths. Ive seen 3 tutorials with this new system using exactly my method except its working, even on of the offical unity tutorials is using my method. I already tried unity 2023.3 and now the unity 6

rich adder
#

i generally dont Set Desitination in update anyway, i call it once and only update if player changes position there is an event and the method is fired again

#

so only as target moves its necessary

jaunty coyote
jaunty coyote
rich adder
#

I mean mine does too, that doesnt mean it has to be in update

jaunty coyote
#

doesnt matter tho, every time the set destination is called, the agent freezes for a second

#

so if a player constantly moves, the character will bassicly constantly try to run setdestination, thus freezed on same pos

#

been there, tried that

rich adder
#

works fine for me, must be something on your end

#

best to debug the path returned and see whats happening, draw the path or check the corners in the gizmos of AI nav

jaunty coyote
#

you able to share your working code?

rich adder
#

i can get to it if I open my project , need some time tho

#

the gist is, if your player is only 1 you can make the public static event Action <float> OnPlayerMove

jaunty coyote
rich adder
jaunty coyote
rich adder
jaunty coyote
#

one single plain terrain

#

debuged line showing correct pathing

rich adder
#

i always get better results when i run the destination through SamplePosition rather than using the target transform postion directy

Vector3 GetDestination(){
 if (NavMesh.SamplePosition(target.position, out var hit, maxHeight, NavMesh.AllAreas))
 {
     return hit.position;
 }
return Vector3.zero;
}```
north oar
#

``public class SpawnCards : MonoBehaviour
{
[SerializeField] GameObject[] cards;

void Start()
{
    StartCoroutine(CardSpawn());
}

IEnumerator CardSpawn()
{
    foreach (GameObject card in cards)
    {
        Animator animator = card.GetComponent<Animator>();
        animator.Play("FloatIn");
    }

    yield return new WaitForSeconds(0.2f);
}

}``
cant figure out the bug in this i have 4 objects im trying to spawn in one by one but they all spawn in at the same time, i use an animation holder to give them all teh same animation

polar acorn
eternal falconBOT
still elm
#

ugh creating a highscore table in unity was more difficult than I imagined

north oar
runic lance
north oar
#

wait im dumb

#

gimme a second lmao

still elm
polar acorn
rich adder
runic lance
#

oops, I thought you were spawning inside the loop, but it's just getting the component

jaunty coyote
north oar
jaunty coyote
still elm
#

a scoreboard who shows how many gameobjects (enemies) I have desstroyed before I died

#

with position and score + name

rich adder
still elm
rich adder
still elm
#

Oh ok

still elm
#

sound like json is used for api

jaunty coyote
#

u want json if you want data to remain after game restart

short hazel
#

It's just a way to "encode" data, you can write it to a file

#

And yeah its original use is from the web, it's in the name: JavaScript Object Notation

rich adder
#

json is irrelevant if its locally or not
as mentioned it just a way to format the data a specific way

#

you can write to raw streams and binary too , up to you

short hazel
#

It's just that JSON is the easiest to set up, and doesn't require much code to save and load the data (10 lines at most)

jaunty coyote
#

@rich adder got it working with: NavMeshPath path = new NavMeshPath();
nm.CalculatePath(temporaryTest.transform.position, path);
nm.path = path;

rich adder
#

also that weird snapping could be cause of character controller being moved with mouse + pivot in playmode

jaunty coyote
#

well it works so i wont touch it, anyways, tnx for your time

jaunty coyote
rich adder
#

hey if it works it works lol

tired knoll
#

is there any reason zero collsion is detected?

#

nothing appears in logs

#

i feel like its a really stupid answer

#

but i actually cannot find it

polar acorn
#

What is the inspector of the object this is supposed to be colliding with

tired knoll
#

the player - i found the reasoning; the object cant collide with anything if probuilder shape is attatched to it

#

which is dumb

stuck palm
#

how come this script isnt working in edit mode?

tired knoll
#

but oh well

stuck palm
#

i dont think its working in playmode either

ivory bobcat
#

What's not working?

stuck palm
tired knoll
ivory bobcat
rich adder
tired knoll
#

idk either

#

i just whacked together a quick sphere and squashed it

rich adder
#

did you have a mesh collider on the pb mesh?

stuck palm
wintry quarry
#

Shader properties almost always start with _

stuck palm
bold plover
#

Why does the color picker in the Karting microgame project freeze my entire computer when I use the color picker lmao.

#

I can only deduce it's old or it's my computer.

steep rose
#

what version of unity are you using

north oar
#
{
    while (Vector3.Distance(player.transform.position, playerSpawnPoint.position) > 0.1f)
    {
        if (Vector3.Distance(player.transform.position, playerSpawnPoint.position) > 0.1f)
        {
            player.transform.position = Vector3.Lerp(player.transform.position, playerSpawnPoint.position, speed * Time.deltaTime);
        }
        yield return null;
    }
}```
i noticed when my player reaches the spawnpoint it starts twitchign and then found out that the while loop actually never stops but i dont know why, it goes direclty onto the spawnpoint
steep rose
bold plover
#

2021.3.22f1

#

The entire computer.

steep rose
#

you physically cannot click anything else?

rich adder
bold plover
#

Correct. I can't even close the program with Alt+F4.

#

Strangeness. No tab out. Nothing.

steep rose
#

does it use all of your ram/cpu/hdd?

#

you should probably check that

bold plover
#

Just reset the computer.

#

Yeah might be a system limitation issue I can't think of anything else.

#

rip

steep rose
#

supposedly this has happened and been known to hang unity but not the entire computer even on unity 2019.

#

if it does happen repeatedly you could probably delete your project library folder to make unity recompile to see if that fixes anything

#

last resort is to reinstall unity

#

if those do not work, just submit a !bug report

eternal falconBOT
#

🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.

📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!

💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.

For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting

steep rose
#

if your system cannot handle the color picker, you should have seen other limitations by now I would think

north oar
bold plover
#

Trying it again. Otherwise I'll probably just end up submitting the bug report.

#

Thank you though.

dim yew
#

why does it tell me to use the first one and then give me an error??

sour fulcrum
#

Is there a built in function/name/etc. for Like rebasing a collection to start from a specific value?

Like imagine i have a list<int> of 0-24

I want to make a version of that list that starts at 22 but everything before 22 is added after 24

#

whoever posted that question yes if i understood correctly

zenith cypress
dim yew
nocturne kayak
#

This is getting stupid and broad but how would one approach colliding without physics? i can move a cube on xyz in 3D space, i don't want it to be affected by any other physical forces, i just want it to collide with walls

#

I did setup a box collider in such a way that it detects when it's colliding with stuff

#

But i can't begin to think how i'd make it so once it's colliding, it can be moved in every direction except for the ones it's colliding with

north kiln
nocturne kayak
#

Is there a way to get the direction of movement if i'm not moving it one axis at a time?

timber tide
#

transform.forward

#

Oh youre moving it in any direction then you should already have the direction anyway. Normalizing your velocity will give direction too.

full coral
#

does anyone know why my .apk build doesnt respond to Click events onto enemies, but it works perfectly fine on my computer, whether it is formatted to windows or android?

carmine sierra
#

How can i capture a mouse's position in unity 3d

wintry quarry
carmine sierra
#

input.mouspos

wintry quarry
#

if the new system, there are several ways depending on what you're trying to do exactly

wintry quarry
carmine sierra
#

but i need to capture it in relation to world space

wintry quarry
#

that's not "capturing the mouse position"

#

that's "how do I project the mouse position into the 3D world"

carmine sierra
#

oh okay

wintry quarry
#

there are several ways, depending on exactly what you want

carmine sierra
#

i need to learn that ray thing dont i

wintry quarry
#

a good third option is just to use the event system, depending on the use case

carmine sierra
#

thanks, i tried cam.ScreenToWorldPoint(input.mousePosition) tho

nocturne kayak
timber tide
#

If you move on the x+ axis your direction vector is simply (1, 0, 0). If you're moving on both the x+ and z+ then your direction vector is (1, 0, 1)

wintry quarry
timber tide
#

which would be 45 degress from the z direction

wintry quarry
#

But you haven't actually explained your use case so

#

it's hard to say what's best

nocturne kayak
#

This whole thing feels stupid, i can't use a character controller because i need a cube\custom collisions, and doing rigidbodies makes the whole thing move around, how come it's so complicated to just move something around and keep collisions, what the hell

wintry quarry
#

It's a very common mistake/misconception for people to think that character controllers are simple

#

they are quite complex

teal viper
# nocturne kayak This whole thing feels stupid, i can't use a character controller because i need...

Well, because you're mixing up different systems here. Collisions are in physics domain. If you want the object to collide with things, it needs to have a collider and a dynamic rb and be moved by the physics. Otherwise there's nothing to calculate the collision for it.
You can obviously reinvent the wheel and write your own collision kind of system with casts and/or overlaps, but that's a different story.

#

It's really not that complicated if you understand and accept the rules of the game.

nocturne kayak
timber tide
#

if all you want is to stop something when it comes into contact then doing shapecasting is probably fine

#

well, I'd do a mix of overlap and shapecast

teal viper
#

Oh, you mean kinematic rb character controller assets on the asset store?

timber tide
#

that asset is also only capsule I think

crisp token
#

Hey I'm having difficulty trying to figure out how to make a constructor for a struct in HLSL on a Compute Shader

crisp token
#

just make a non-official constructor seems to be thje play

sand girder
#

bro i cant even code😭 😭

teal viper
sand girder
#

HOW THE HELL DO I CODE

#

I CANT EVEN CODE ANYTHING TO WALK

teal viper
eternal falconBOT
#

:teacher: Unity Learn ↗

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

sand girder
#

ok

crisp token
teal viper
crisp token
molten pulsar
#

hi im having a problem

#

im trying to modify avatar herarchy becuse unity imports make it a mess

#

when i finish and exit from avatar configuration

#

avatar herarchy didnt save

#

how i can save it?

teal viper
lost anvil
#

is it bad to have a script dedicated to references for use within a namespace / state machine?

teal viper
molten pulsar
teal viper
molten pulsar
#

thank you for that

#

i never think in that before

lost anvil
molten pulsar
#

soo i unpack the model modifiy and save it as new prefab but that dosent seems to be usefull,theres a way that i can create a avatar from a unpack model in scene?

teal viper
molten pulsar
#

so was a mistake post this in this chanel

#

btw

#

im trying to fix this:

#

and well the only way that i find to fix it was change the jerarchy but

#

when i leave avatar configuration dont save it

teal viper
molten pulsar
#

sooo i blender see normaly

#

i have to change jerarchy in blender?

teal viper
# molten pulsar i have to change jerarchy in blender?

Yes. Make sure it confirms with the standard humanoid armature. At the moment it does not. You have shoulders and fingers parented to the root of the armature. This is not correct even in blender(though it might just work in blender).

molten pulsar
#

i will try that

#

i say you if that works

static cedar
#

How to get the width and height of a rect transform? UnityChanThink
It's surprisingly more complex than i thought.

timber tide
#

rect

static cedar
#

Apparently not. Because it also depends on anchor position.

stark sonnet
signal egret
teal viper
stark sonnet
#

i didn't. i'm new to all this and learning through tutorials. unfortunately this one didn't provide much explanation. i will try that. thank you

signal egret
#

do

  velocity.y += gravity;```
teal viper
stark sonnet
teal viper
stark sonnet
stark sonnet
signal egret
#

your grounded is much more reliable if its a raycast
grounded = Physics.Raycast(pos, Vector3.Down, charHeight, ~whatEverThePlayerLayer, out var hit)

teal viper
signal egret
#

hit is helpful if you want more information what ever the ground is, steps sounds, slippery surface etc

stark sonnet
stark sonnet
# teal viper Can you share the tutorial?

#survivalgame #tutorial #unity
In this tutorial series, we will create a 3D survival game with Unity & C# as the scripting language.
We are going to start with basic FPS movement, build an inventory, and crafting systems.
Learn how to pick up items and more.
Little by little, we are going to add different features that are common to survival op...

▶ Play video
bitter sage
#

So I'm using the Facepunch Steamworks Steam Integration plugin in Unity, and got steam integration working and everything in my game.

The problem is, my game crashes if the game is run outside of Steam now and also there are compiling errors on Non-Steam platforms, such as WebGL or Android. I'm not exactly sure how to solve this. I thought removing the Steam Integration script would do it, but it didn't.

Has anybody had any experience with this? I seem to be having trouble exporting to a DRM-Free executable for itch.io and non-Steam platforms such as WebGL and Android.

teal viper
stark sonnet
spare mountain
bitter sage
#

Putting the Steamintegration files and everything back made it all work again

#

no crashes

stark sonnet
# teal viper Where's the part that they explain/implement jump?

he starts to explain the script at about 28:00 and goes through and explains how to set up the ground check/ground mask , stuff like that. the guy was a little all over the place by the end he shows hes walking and jumping. i'm able to move but jumping for some reason is just not working

teal viper
teal viper
stark sonnet
teal viper
# stark sonnet

Okay.
Let's get started with debugging a little bit then.
First, you want to make sure that there are no errors at runtime. Especially no errors popping up at around the time of the issue.

#

I see you have an error in the console right now. What is it about?

stark sonnet
teal viper
stark sonnet
teal viper
# stark sonnet that is correct

Okay. The next thing is where to start debugging and how.
There are many ways to debug code. The simplest one is printing something in the console that would tell you about the state of the objects at that time. You can do that by using Debug.Log("some text");. You can pass in whatever string you want. You can output other variables values and almost anything else.

Now. Debugging is a 2 stage process:

  1. You make an assumption.
  2. You confirm the assumption with debugging info, like debug.log.

In your case we can start with a very simple assumption: the code that sets the jump velocity doesn't run.

Now, how can we confirm that with a debug.log?

stark sonnet
#

would i run the debug.log after
if (Input.GetButtonDown("Jump") && isGrounded)
{
//the equation for jumping
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);

}

stark sonnet
#

after that bit of code?

#

isn't that the lines of code for jumping?

teal viper
#

And another question: what do if statements do?

stark sonnet
#

if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}

#

they determine whether or not something is true, right? like i have an if statement stating that if i press say the spacebar to jump that statement will run because its true?

teal viper
stark sonnet
teal viper
#

You would place it directly after the line that you want to confirm. In this case it happens to be in the if block.

stark sonnet
#

okay i will try that now

stark sonnet
#

this is the correct way to put it right?

teal viper
#

No. Go over what we were talking about again.

#

Would that log prove that the line inside the if block runs?

stark sonnet
#

no. when i placed it on the inside nothing showed up in the console when i tried to jump

teal viper
#

So what can we conclude regarding the first assumption?

stark sonnet
#

that line of script is not running

teal viper
#

Great. Now let's move to the next assumption. Why is it not running?

stark sonnet
#

maybe it's not meeting all the parameters of the isGrounded?

#

isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

teal viper
stark sonnet
#

🤦‍♀️

#

something is wrong with that block so that block needs to be tweaked. correct? i do that before the parameters?

teal viper
stark sonnet
#

thats correct

teal viper
#

So you should start with seeing which condition is being false.

stark sonnet
#

okay. so i'm getting the feeling then that its not grounded then

teal viper
#

Okay. And how would you confirm that assumption?

stark sonnet
#

debug.log after the line that determines if grounded?

teal viper
#

It would be simpler to print the value of the variable

#

Debug.Log("some variable value is " + someVariable);

willow shoal
#

Hi. how to make the box collider work whenever I am in?

#

I tried using ontrigger, but it only worked once

eager spindle
#

ontriggerenter works when you enter

#

ontriggerexit works when you leave

#

ontriggerstay works anytime

willow shoal
#

Thanks

#

I will try

tulip nimbus
#

Not sure if one can see in this video but whenever i control my camera it kind of stutters, making the camera movement less smooth. Why is this? (Wether putting it in FixedUpdate() or Update() didnt seem to make a diffrence for me)

What can i do?

tulip nimbus
#

Thank you 👍👍

waxen adder
rancid tinsel
#

what is going on here? if i copy and paste that line in again it suddenly doesnt throw an error

north kiln
rancid tinsel
#

same exact line same format

north kiln
#

In the same file?

rancid tinsel
#

yes

north kiln
#

Perhaps it's a busted character

rancid tinsel
#

just pasted in place of the one throwing an error

#

what do you mean by that?

north kiln
#

Firstly, you definitely have the correct using?

rancid tinsel
#

yes

#

UnityEngine.Pool

#

im following a tutorial to the T rn

north kiln
#

That's not the using for List

rancid tinsel
#

UnityEngine?

north kiln
#

Nope.

rancid tinsel
#

System.Collections.Generic?

north kiln
#

Yes

rancid tinsel
#

ok then i do have it

north kiln
#

So then it's probably just a foreign character

#

As you say just re-writing it fixes it, seems likely to be that

rancid tinsel
#

copy and pasting fixes it

#

so that wouldn't make sense

#

wait

#

wtf

#

i just realised what it is

#

for some reason typing it doesn't add the using

#

and pasting it does

#

so it was just missing..

north kiln
#

Typing it would add it if you used autocomplete instead of character-by-character

rancid tinsel
#

thank you for the help

north kiln
#

otherwise, as the doc I linked said you should use your IDE to add namespaces

rancid tinsel
#

the one issue with that is it keeps autocompleting and adding random stuff i dont want and makes it messy

frozen burrow
#

Hello I have this code that lerps between two colors, however they change gradually like a gradient. How can I change it so it changes instantly? I probably shouldn't use Lerp but I don't have much options in the props/funcs of Color.

keen dew
#

You mean it should alter between the two colors?

vernal bone
#

Hi, have a small question.

Should i unsub events in OnDisable?
Like it's necessary/best practice or i just randomly picked that up somewhere?
UnityChanHuh

winter aspen
vernal bone
winter aspen
#

you're welcome 😄

north kiln
#

If you're referencing other objects from an event on the destroyed object then because the C# side remains in memory when referenced at all then that other object will too and they won't be GC'd until all the refs are assigned to null

carmine sierra
#

why doesnt this work

north kiln
carmine sierra
#

but rb.velocity.normalized doesnt work

north kiln
#

how so?

carmine sierra
#

says vector3 is not assignable to float

north kiln
#

so you're trying to assign a it incorrectly. Have a look at the broader picture and look at what you're assigning to

vernal bone
carmine sierra
#

i want a magnitude which is limited to 1

north kiln
carmine sierra
#

which is what i thought normalization did

#

that would just give it a limit of 1 right

north kiln
#

yes, clamp between 0 and 1

#

Mathf.Min(value, 1) would be the same

#

as magnitide is always positive, would be less checks

carmine sierra
#

ohh okay rb.velocity.normalized.magnitude works

north kiln
#

that will always be 1

#

(or 0, but nothing inbetween)

carmine sierra
#

oh?

#

if I want rotation in one axis around another object (according to mouse velocity and position) what method could I use?

#

I tried rotatearound but im not sure how to get it relying upon the mouse's movements

past spindle
#

If I create an invisible collider around an explosion and only activated it during the explosion, could I use OnTriggerEnter to create an Area of Effect to damage the player if the player is within the trigger area when it is activated?

keen dew
#

It would be much simpler to use OverlapSphere or OverlapCircle

past spindle
#

Ok thanks

frozen burrow
keen dew
#
colors.selectedColor = (int)(Time.unscaledTime * colorSpeed) % 2 == 0 ? startColor : endColor;
#

or if you divide by colorSpeed instead of multiplying then colorSpeed is the time in seconds how long one color is selected

frank pelican
#

does anybody know why i dont have any decent rider code inteligence

#

everything is white and i dont have any tabcomplete for some reason?

slender nymph
#

!ide

eternal falconBOT
frozen burrow
wind raptor
#

How quickly does the console update? I feel like I'm seeing delays between calling Debug.Log and seeing it on the console, but I'm not 100% sure it's the console being delayed vs something I've done.

fickle halo
#

with static classes, why is static required for members? When the static class already prevents all members from being non-statics?

wintry quarry
#

C# was designed by microsoft. It was a language design decision they made that you still have to type static for all members

#

presumably for clarity

#

When you're on line 600 of a 2000 line file it might not always be immediately obvious you're inside a static class.

fickle halo
#

heh ok

#

why can't I put constant variables in a namespace??

languid spire
#

why are you asking nonsensical non Unity questions on this server?

summer shard
#

why does my smooth damp stutters when i move?? it's in update

heldPickable.transform.position = Vector3.SmoothDamp(heldPickable.transform.position, objectHolder.position, ref handDampVelocity, handPositionSmoothTime);
odd widget
#

If i were to have a list of variable that’s often refetenced by a lot of other script, is the better practice to separate it from the original script so the other script reference that instead?

languid spire
#

makes absolutely no difference

odd widget
#

Aaah okay then

#

Thanks

slender nymph
fickle halo
#

my hunch is those courses won't have an answer to that question

#

wrong channel though, i get it.

languid spire
#

the answer is the same as to your previous question. Because that is the way the language was designed and implemented. If you don't like that take it up with Microsoft, this server is not the place to ask such questions

wintry quarry
#

Show the rest of the code as well

summer shard
wintry quarry
#

yes

summer shard
wintry quarry
#

Ok and the other question?

summer shard
# wintry quarry Ok and the other question?

object holder is under main camera, this is the inspector, heldPickable is just a Pickable script reference of held pickable in hand, i can send a vid of how it's looking rn

Pickable heldPickable = inventory[heldInventoryIndex];
if (!Input.GetKey(KeyCode.Mouse1)) {
    //lerp here
    heldPickable.transform.position = Vector3.SmoothDamp(heldPickable.transform.position, objectHolder.position, ref handDampVelocity, handPositionSmoothTime);
    heldPickable.transform.rotation = Quaternion.Slerp(heldPickable.transform.rotation, objectHolder.rotation, handRotationSmoothTime);
}
summer shard
# wintry quarry how does the player move
#region MOVEMENT
private void HandleCamera() {
    if (!canLook) return;

    float mouseX = Input.GetAxis("Mouse X") * sensitivity;
    float mouseY = Input.GetAxis("Mouse Y") * sensitivity;

    cameraLook.y += mouseX;
    cameraLook.x -= mouseY;

    cameraLook.x = Mathf.Clamp(cameraLook.x, -85f, 85f);

    cameraHolder.localRotation = Quaternion.Euler(cameraLook.x, cameraLook.y, 0);
}

void HandleAir() {
    isInAir = !Physics.CheckSphere(groundCheckTransform.position, 0.1f, groundLayer);
    playerRigidbody.linearDamping = isInAir ? 0f : 10f;
}

void HandleMovement() {
    if (playerRigidbody == null || !canMove) return;
    isRunning = Input.GetKey(KeyCode.LeftShift);

    Vector3 cameraForward = new Vector3(cameraHolder.forward.x, 0, cameraHolder.forward.z);
    Vector3 cameraRight = new Vector3(cameraHolder.right.x, 0, cameraHolder.right.z);

    float horizontal = Input.GetAxisRaw("Horizontal");
    float vertical = Input.GetAxisRaw("Vertical");

    Vector3 move = cameraForward.normalized * vertical + cameraRight.normalized * horizontal;
    move.y = 0;
    moveDirection = move.normalized;
    playerRigidbody.AddForce(move.normalized * (isRunning ? runSpeed : moveSpeed));
}
#endregion
wintry quarry
#

Does the Rigidbody have interpolation enabled?

summer shard
wintry quarry
#

not sure

#

yu might have some other code breaking the player's interpolation potentially

#

something like that

#

wait

#

does the held object have a Rigidbody?

summer shard
summer shard
wintry quarry
#

but not to true when you pickup

summer shard
#

it does

summer shard
wintry quarry
#

not exactly sure then

#

I would try removing the Rigidbody component in the inspector while testing

#

while holdling it

#

and seeing if that changes anything

summer shard
#

hmm it sure is smoother but i can't disable the rigidbody, i can only remove it

fickle halo
#

i installed plastic scm in vscode, but i dont see any highlighted lines for changes?

summer shard
fickle halo
#

its unity's version control

summer shard
#

ohh

fickle halo
#

Plastic SCM extension can't start: unable to start "cm shell"

#

this is the error im getting. on macos

summer shard
quaint storm
#

Hey, everyone! I'm making a game with a complicated reload mechanic, you gotta use your mouse to eject mag, insert a new one and drag the slide. I'm fairly new to unity, but I have no clue where to start. I have already implemented every other mechanic except this one.

#

Any hint on where to start or some learning materials to read up on are appreciated.

#

Also, this is for a project and the dead line for this mechanic was a week ago, but I was able to delay it till the next week.

icy blade
#

quick question, i want to put a picture with jpg file into panel, but the source image doesn't recognize my image can you help me

#

also the core im using is 3d core

wintry quarry
icy blade
languid spire
icy blade
full coral
#

Is there any way to fix NiceIO, I think it's breaking my apk build

long jacinth
#

why doesnt this work

rich adder
languid spire
rich adder
#

also bad idea to GetComponent in update. Cache it in awake/start

polar acorn
rich adder
#

is just probably Image from wrong namespace

long jacinth
#

how do i get the color tho

polar acorn
long jacinth
rich adder
polar acorn
lofty sequoia
#

is there a way to search for child/derived prefab variants?

long jacinth
#

i changed it but its not telling me any way to change the color of an image

polar acorn
lofty sequoia
#

inspector, runtime I'd probably have to iterate assets for a type-- although that's assuming each one has the same type in it

rich adder
languid spire
polar acorn
long jacinth
#

Image' does not contain a definition for 'Color' and no accessible extension method 'Color' accepting a first argument of type 'Image' could be found (are you missing a using directive or an assembly reference?)CS1061

rich adder
slender nymph
polar acorn
long jacinth
rich adder
wintry quarry
#

Yes, but also anyone can make one

long jacinth
#

no i dont have a script named image

#

Microsoft.Unity.VisualStudio.Editor.Image

wintry quarry
#

Definitely wrong one

rich adder
polar acorn
long jacinth
#

now it works thanks

#

is there a way to make the color more whiter

#

for any color

rich adder
#

whiter?

polar acorn
#

Make the color closer to #FFFFFF

rich adder
#

.color just tints the sprite btw. It doesn't change the original sprites color

long jacinth
polar acorn
long jacinth
#

how is that achievable if its just gonna be numbers and letter in code

polar acorn
#

By picking numbers closer to #FFFFFF

wintry quarry
#

quick dirty example

Color Whiten(Color input) {
  Color.RGBtoHSV(input, out float h, out float s, out float v);
  s -= .1f;
  v += .1f;
  return Color.HSVtoRGB(h, s, v);
}```
wet lark
#

hello just wanted to get a quick understanding of PPU setting, just started learning and so i sliced a 16x16 tileset for the world and a 32x32 sprite sheet for my player and set PPU for to 16 and 32 respectively, but wondering why when i build the world through my tile pallette my world building tiles are basically like double the size of my Player sprite, did it scale to the max PPU?

swift sedge
swift sedge
#

or just use a hex -> dec converter online

long jacinth
wintry quarry
#

which brings it closer to grayscale

#

and then brightening it moves it towards the white end of the grayscale

#

(as opposed to the black end)

#

it really depends on exactly what effect you want

#

but some combination of desaturation and brightening is what you want

#

you can also just brighten and leave the saturation alone, or vice versa

long jacinth
#

the background is black so just simply lowering the alpha will make things darker

#

but i dont know what is better making things darker or brighter for my game because it will only affect the capital state so it is brighter and can be differenciated from the others

swift sedge
#

hsv is what you want

long jacinth
#

alright thanks

bold plover
#

Trying to add a player input component to my player object. It doesn't seem to not be wanting to find that though. I guess I reinstall packages?

languid spire
#

have you created and generated one?

past spindle
#

Could somebody look at my code. I'm working with OverlapSphere for the first time but not getting the result I'm after. This script is on the objects exploding and I'm trying to create a space for dealing damage & knockback to the player, but the debug.log message isn't even printing in the console window. https://hatebin.com/lopfahkyhd

polar acorn
past spindle
#

@polar acorn Do you mean to put it one level up? And yes, the other debug.logs work fine

polar acorn
#

Inside the loop, outside the if. See if the overlap picks up anything, and then find out which objects it hits if it does

past spindle
#

I’m not sure how to return that info.

#

How do you tap into what the loop detects?

polar acorn
#

by logging it

rocky canyon
#
    Collider[] colliders = Physics.OverlapSphere(transform.position, 3f);
    foreach (Collider c in colliders)
    {
        Debug.Log($"Detected: {c.gameObject.name}");

        if (c.GetComponent<BoxController>())
        {
            Debug.Log("Player takes damage.");
        }
    }```
past spindle
#

It's detecting all the colliders that make up my player. My player is the only object in the game so far.

polar acorn
past spindle
#

@rocky canyon thank you

swift sedge
rocky canyon
#

print is gross and inferior

#

but yes, u could

#

i'll use print when coding console
in unity always use Debug.. Dbug rather 😈

rocky canyon
#

helps isolate and see where problems may arise

past spindle
#

@polar acorn Only one object has BoxController, and it is showing that the script is detecting it

rocky canyon
#

thats good news right?

polar acorn
rocky canyon
#
        if (c.TryGetComponent<BoxController>(out BoxController boxController))
        {
            Debug.Log("Player takes damage.");
            boxController.DoSomething();
        }
        else
        {
            Debug.Log($"No BoxController found on {c.gameObject.name}");
        }```
may also consider using a TryGet vs GetComponent but thats something u can look into later
past spindle
#

@polar acorn ok, I think I see the problem now. The collider has been deactivated for the object holding the script to allow objects to enter the object, but I can work around that. Thank you.

cosmic quail
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

sage mirage
#

Hey, guys! Is there a way somehow to bypass time.timescale and do something ? For example, I have some animations that I want to run when time.timescale is 0 how I can do that ?

slender nymph
#

set your animator to use unscaled time

sage mirage
#

Yeah but what about dotween?

#

I am animating game objects with DoTween. Is there a way to make it, when working with DoTween?

thorny basalt
sage mirage
rich adder
sage mirage
#

Of dotween?

slender nymph
#

yes, obviously

sage mirage
#

Yeah I have checked

thorny basalt
sage mirage
#

There are different methods

rich adder
thorny basalt
#

Neat. I never manipulate timescale so I don’t know. 😅

rich adder
#

pew pew slow mooo

slender nymph
sage mirage
#

You know I have some UI elements that I am scaling, so what I want is to ignore timescale and reset it's size back to it's default size

#

There is a method for it

slender nymph
#

so check the docs for the tweening library you are using to perform that action so you can find out how you can use the unscaled time

sage mirage
#

SetUpdate(true)

#

DoScale().SetUpdate

slender nymph
#

don't expect people here to look at the docs for an asset you are using for you

thorny basalt
#

static bool DOTween.defaultTimeScaleIndependent
Default: false
Sets whether Unity's timeScale/maximumDeltaTime should be taken into account

rich adder
#

yea thats in the docs

slender nymph
#

it's also not what they probably want, the method they already found is probably the one they want. unless they want to affect all newly created tweens

rich adder
#

^ those are global settings

sage mirage
slender nymph
#

look harder then

rich adder
#

I hate their docs ngl

#

they don't have anchoring links

sage mirage
#

Yeah I don't use very often do tween this is like my 2-3 time

rich adder
#

literally go on their page and search TimeScale

#

it aint hard

sage mirage
#

I am using everytime Unity Docs ok I have to learn searching on dotween docs

rich adder
slender nymph
#

learn how to use ctrl+f

rich adder
#

the browser has built in ^

sage mirage
#

ctrl + f?

#

What is that

#

What it does?

#

In visual studio

slender nymph
#

you know google exists too, right?

rich adder
sage mirage
#

Yeah bro I just want to talk

rich adder
#

dev tricks you need to learn

sage mirage
#

I don't want help from google neither chat gpt I prefer getting help from people XD

rich adder
#

google helps you be self sufficient

slender nymph
#

the first dev trick you need to learn is actually googling things you don't understand as the first option rather than immediately asking other people

polar acorn
summer shard
#

what's better dotween or leantween

slender nymph
#

primetween

sage mirage
summer shard
polar acorn
#

"Guidance in order to do it on my own" is what we are telling you to do

slender nymph
sage mirage
#

I said that I am not familiar with do tween docs no?

slender nymph
#

and that is why you use ctrl+f

rich adder
#

yeah but you can search any docs if you learn the tools that exist to do so

#

as such it was pointed out multiple times you can search within browser

polar acorn
sage mirage
#

Wait you can do that everywhere ctrl + f?

#

I know different shortcuts but this one was really strange for me

rich adder
#

no

#

i mean most browser use that as shortcut
these are the more important things that you should learn and will boost your productivity 200%

summer shard
#

also should i use tweens to animate "HeldObject" moving up and down to simulate getting the object from your pocket or should i use just animator

rich adder
summer shard
sage mirage
#

There are also different shortcuts in Unity that boosts productivity but I really can't remember all of them only few of them or I just have to use them more often in order to remember them next time.

polar acorn
rich adder
summer shard
rich adder
#

its just whatever is going to be easier for you to make ,

#

if you plan on having a lot of items, all you need to do is animate 1 thing anyway the object holder

polar acorn
swift sedge
polar acorn
#

Roll dice if need be

rich adder
#

hehe I do that sometimes ^

wraith phoenix
#

Hey all,
Super simple question but how do I code an Attack() that simply moves an enemy towards the player?

polar acorn
wraith phoenix
#

I found this and was about to try it.
Unless you have a more robust way to implement it?

polar acorn
wintry quarry
wraith phoenix
#

The game is 2d top down isometric, if that helps to know

#

This is moving my enemies currently:
rb.MovePosition(rb.position + (moveDirection * (moveSpeed * Time.fixedDeltaTime)));

wintry quarry
wraith phoenix
#

This might also respect the collisions unintentionally

#

But I'll play with changing to rb.velocity

wintry quarry
sharp pawn
#

So if I have the code line
Private void OnTriggerEnter (Collider other)
How would I change the that so that the code contained in the void is activated every frame that the player is in that trigger?

slender nymph
#

use OnTriggerStay instead (that is called each physics update that the trigger collider overlaps another collider)

sharp pawn
#

Ah thank you

wraith phoenix
#

What's the proper format for posting code again? !code

eternal falconBOT
wraith phoenix
#
{
    [SerializeField] private float chaseSpeed = 3f;

    private GameObject player;
    private Rigidbody2D rb;
    
    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody2D>(); 
        player = GameObject.FindGameObjectWithTag("Player");
    }

    // Update is called once per frame
    void Update()
    {
        rb.velocity = Vector2.MoveTowards(transform.position, player.transform.position, chaseSpeed * Time.deltaTime);
    }
}```
slender nymph
#

Vector2.MoveTowards(transform.position, player.transform.position
this does not make sense for velocity

wraith phoenix
#

This is what I came up with. Trying it now.
P.S. Sorry for posting a screenshot of code earlier. Now I no to not do so.

wraith phoenix
#

So then do I need to return to moving the enemy by their transform?

slender nymph
#

no. praetor suggested using the movedirection multiplied by your desired speed for the velocity, that is not what you have here

#

direction is (endPosition - startPosition).normalized

wraith phoenix
slender nymph
#

no, you don't need the MoveTowards call at all if you are assigning velocity

#

also i just told you how to get the direction. then you just multiply that by the speed and voila you have the velocity

wraith phoenix
#

rb.velocity = (player.transform.position - transform.position).normalized * (chaseSpeed * Time.deltaTime);

#

Like this?

slender nymph
#

don't use deltaTime when assigning velocity unless your intention is to move very very slow

wraith phoenix
#

Ok testing now

#

Thank you so much!

slender nymph
wraith phoenix
#

Good to know that velocity is already expressed in units per second. So whenever I'm not working with velocity, go back to deltaTime.

wintry quarry
wraith phoenix
rocky canyon
#

this like for example.. in Update (can vary how often its run)
if ur doing something like :
myValue = otherValue * 10; it could vary
so, in that case you'd do something like :
myValue = otherValue * 10 * Time.deltaTime;

wraith phoenix
#

I did a dirty work around and it works!

#

THank youi so much

#

Feeling accomplished and logging off

red wind
#

Why cant I see my Particals in my Game?

slender nymph
#
  1. not a code question
  2. that big white rectangle you are looking at is your canvas, not your camera. your camera is the itty bitty rectangle where your move handles are centered on so you need to make sure your particles are visible in that
slender nymph
#

please tell me your solution wasn't to make your camera 100x bigger to fit around the canvas

swift sedge
#

make the canvas relative to the camera via the "Render Mode" property. At least for 2D

young lava
#

Alright so pretty much I've been implementing a map system. When you press M, the full map is pulled up and you can click and drag to pan the map around to see parts that might not fit on the entire UI. I am in the middle of implementing a fast travel system, but I am having trouble implementing it. The minimap UI itself is literally just a mask and a texture to display what the MapCamera is seeing (the map camera is seeing all the different gameObjects in the scene with map icons attached to those gameObjects). Pretty much what I want is if the mouse is pretty close to the TP icon on the map, and the player clicks, the player will fast travel to that TP. The only issue is that since the map is not made up of all the icons itself I can't really use a button or anything to implement this. I would probably need to somehow calculate the click on the map and convert that to world position. Is this a viable method or should I swap to a different one?

ivory saffron
#

I need an event similar to OnPointerClick, but it needs to fire on button down, instead of waiting till button up

slender nymph
#

IPointerDownHandler with its OnPointerDown method

ivory saffron
#

thanks

lofty sequoia
#

Is it possible to change center of a sprite to the pivot point?

#

I thought maybe
image.rectTransform.pivot = image.sprite.pivot;
would maybe do something useful, but when the prefabs are instantiated, the pivot of the sprite changes and sends it way off screen

knotty arch
#

Hello. I'm not sure if I'm using Time.deltaTime correctly.

void Update()
    {
       Vector2 movement = getMovement().normalized;
        if (movement.x != 0 || movement.y != 0)
        {
            rb2D.velocity = Speed * Time.deltaTime * movement;
            animator.SetFloat("DirY", movement.y);
            animator.SetFloat("DirX", movement.x);
            animator.SetBool("Idle", false);
        }

I'm changing the FPS manually to see how the game reacts to different perfomances. The enemies seems good, but the player moves extremely fast (while "teleporting" because of the low framerate). So, I guess that the Time.deltaTime doesn't has to be here but I can't understand why.

#

If I don't use Time.deltaTime, then my movement won't be framerate-dependant, does it?

knotty arch
teal viper
eternal needle
knotty arch
eternal needle
#

Input can be in update, movement can still be in fixed update

knotty arch
knotty arch
teal viper
#

See the issue?

knotty arch
teal viper
#

So it's not velocity anymore

#

You're basically assigning the distance to be moved that frame to velocity.

knotty arch
#

Am I right?

teal viper
knotty arch
#

Thanks for you help 🫡

teal viper
knotty arch
#

I will try it

eternal needle
#

Unless the movement has some easing I guess

ivory saffron
#

what's the issue here ?

wintry quarry
ivory saffron
#

no

wintry quarry
#

you sure? Because that error doesn't really seem likely on that line

#

can you run it again and see if it still says line 37?

#

(and make sure all code is saved)

ivory saffron
#

yes i'm pretty sure it's on that line

wintry quarry
#

did you run it again?

ivory saffron
#

it was on line 35 once though

wintry quarry
#

Does it still say line 37?

#

Run it again now

#

I think you added the log line or something

ivory saffron
#

yes i did run it again. going to restart unity now

wintry quarry
#

most likely the error is on line 36 in that screenshot

#

and likely owner.itemHolder is null, based on that log.

wintry quarry
#

restarting Unity isn't going to do anything for this

ivory saffron
#

it did

wintry quarry
#

line 36

#

so yeah owner.itemHolder is null

north kiln
#

prefab might be, as it's coming from Instantiate

ivory saffron
#

it's not null

wintry quarry
wintry quarry
north kiln
#

It could even be a field on prefab that's borked

wintry quarry
#

but it seems to me almost certainly owner.itemHolder

north kiln
#

a serialized backing field of a property called empty

#

on a component called PrefabsReference

north kiln
ivory saffron
#

right, empty was null

wintry quarry
wintry quarry
#

I was working off that old information

ivory saffron
#

we're back to screenshot 1 now

wintry quarry
ionic raven
#
public void amountChanged(ChangeEvent<string> evt)
{
    decimalPlaces = maxDecimalPlaces;

    bool usedPeriod = false;
    char[] allowedChars = "0123456789.".ToCharArray();
    string result = "";
    var amount = Tamount.value;

    foreach(var c in amount)
    {
        if (c.ToString() == "." && !usedPeriod) // if it is "." and not been used
        {
            usedPeriod = true;
            result += c;
        }
        else if(c.ToString() != ".") // it's not "."
        {
            if (decimalPlaces > 0)
            {
                if (allowedChars.Contains(c))
                {
                    result += c;
                }
            }
            if (usedPeriod)
            {
                decimalPlaces--;
            }
        }
    }
    string zeros = "";
    for(int i = 0; i < decimalPlaces; i++)
    {
        zeros += "0";
    }
    Debug.Log(zeros);
    result += zeros;

    Tamount.value = result;
}

The very end where i create the zeros string is causing my unity to crash, what can i fix here?

wintry quarry
ionic raven
#

Starts off as 4

wintry quarry
#

how do you know though

ionic raven
#
    [Range(0,4)]
    public int maxDecimalPlaces = 4;
wintry quarry
#

that doesn't tell us anything

#

it can be serialized as any value

#

use the debugger or Debug.Log to print it

#

(btw using StringBuilder would be massively more efficient than this code)

ivory bobcat
#

Check the value in the inspector and probably log the value before the if statement.
Might want to comment out the for-loop if crashing will occur or run with the debugger etc

ionic raven
#

just opening it again

#

decimal places is at 4 before the if statement

ivory bobcat
#

And before it crashes, what is the value?

ionic raven
ivory bobcat
#

You can use the debugger to set a break point after it crashes to stop the application without having to reboot the editor

ionic raven
north kiln
#

Tamount's changed callback is amountChanged, isn't it.

wintry quarry
#

Ah yeah - is that a text input field or something

north kiln
#

Use SetValueWithoutNotify, or whatever the appropriate function is

ionic raven
#

instead of Tamount.value?

ionic raven
ivory bobcat
#

When you update the value it'll call the function again - endlessly.

ionic raven
#

OHHHHHHHHHH yes, that makes sense hahahaha

#

so withoutnotify is changing it but not calling the amountChanged yeah?

#

Lovely! It works! Thank you all!

#

In the input field, i want to put a "$" at the start, but i can select before the "$" sign, how do i select after it?

ivory bobcat
ionic raven
#

The line on the left is my cursor, is there a way to make it so the cursor is always in front of the $

rich adder
ivory bobcat
#

Maybe you ought to put a label object next to the text field

ionic raven
#

alright aha, i'll give that a go 🙂

rich adder
#

make sure to anchor them together

ionic raven
#

Is anchor in the toolkit?

ionic raven
#

I haven't seen it in the unity toolkit

rich adder
#

oh you're using UIToolkit?

ionic raven
#

yeahh

rich adder
#

ahh okay 😅 no idea ig its fine if they're using flex layout or something, I never used it for ingame just editor

ionic raven
#

I have only just started using the toolkit since using the other UI, it is so different 😂

#

This is as close as I know how to get

rich adder
#

you should be able to modify the padding

ionic raven
#

And it is indented from the others

rich adder
#

very different lol they have 3 different ways to layout too, including a layout editor

ivory bobcat
#

Online suggestions for anchoring with ui toolkit:
https://discussions.unity.com/t/do-the-ui-toolkit-has-an-anchor-option/943211/5

Create an empty container with the current container inside of it. Set Position to absolute, click on the small box in the larger box to attach it to all the edges of the screen, and then in Flex set the direction to be from that edge.
or
use flex-direction to position a container visual element for the player status elements at the bottom, using column-reverse on its parent element.

rich adder
ionic raven
#

I don't think it is padding because that's all set to 0 and negatives don't do anything

rich adder
#

its probably margin n stuff

north kiln
#

you will need to make a selector that targets the relevant element

#

by padding the container that wraps the inner text

ionic raven
ionic raven
#

using margins i can get this:

ionic raven
primal rivet
#

Guys to learn code i just need to look at pins in script channels right?

queen adder
#

ok

#

so basically

#

im 2d rigidbody, with box collider 2d and a player script that my teacher provided

eternal falconBOT
queen adder
#

of the script?

rich adder
#

the script is the code yes

queen adder
#

alr

#

wait

rich adder
queen adder
#

ok

#

wait

rich adder
rich adder
#

and the rigidbody

queen adder
rich adder
#

that gravity scale is pretty high

queen adder
queen adder
#

it's just the horizontal movement, jumping is fine in the build

rich adder
queen adder
rich adder
#

change Update to FixedUpdate

queen adder
#

where

rich adder
#

in the Player

queen adder
#

ok

rich adder
#

I think your speed is probably just too low for the amount of drag you put

#

either crank up speed or lower drag

queen adder
#

ok

#

ty

rich adder
queen adder
#

im trying

queen adder
rich adder
#

if you want to keep same speed just lower the linear drag

queen adder
rich adder
queen adder
#

ok

frank zodiac
#

I dont get the point of a "private backing field". I did a bit of research and found that it controls access to a value, but cant we just use a simple get and set on a field without a private backing field, and wouldnt that technically be considered "controlling access to a value"?

north kiln
frank zodiac
north kiln
#

(unless you're on a very new version of C# that we're not on)

north kiln
frank zodiac
#

Arent get and set basically mini functions that execute whenever the property is gotten or setten, respectively?

#

So we could put any logic we want in there

north kiln
#

But what's the value if you've declared the body of the function

#

if you don't declare the body then an implicit backing field is created and used

#

if you do, then no field is created and you are required to do that yourself

frank zodiac
#

Could you give an example plz?

#

I dont really get it

north kiln
#

public Example Blah { get; set; }
This field is backed by an implicitly created field called <Blah>__backingField (off the top of my head)

#

and it creates two functions,
Blah__get() and Blah__set() which retrieve and set that backing field

#

if you do:

public Example Blah
{
  get {
    // insert code here ...
  }
  set {
    // insert code here ...
  }
}
#

there is no implicit backing field

#

and so there is no value, hence why if you want to do something similar to the other one but with some checks on top you need your own field

#
private Example _blah;
public Example Blah
{
  get => _blah;
  set {
    if(_blah == null)
      throw new Exception("Bad!");
    _blah = value;
  }
}
#

public Example Blah { get; set; }
is just shorthand for

private Example <Blah>__backingField;
public Example Blah
{
  get => <Blah>__backingField;
  set => <Blah>__backingField = value;
}
#

except the compiler is doing the work for you

frank zodiac
#

Ah I see now

#

Makes sense, thanks

ionic raven
#

How do I sort the list entries by date:

using System.Linq;
using UnityEngine;

public class EntryManager : MonoBehaviour
{
    [SerializeField]
    public List<Entry> entries;
    
    [System.Serializable]
    public struct Entry
    {
        public string amount;
        public string payer;
        public string date; // Format "dd/MM/yyyy"
    }
}
ivory bobcat
eternal needle
fossil valley
#

Hey guys quick question. Can someone explain Why do we have to put () at the end of this code---- animator.SetBool(IS_WALKING, player.IsWalking());

eternal needle
fossil valley
#

The player is referencing another scripts function. I'm just trying to understand why we have to put that at the end? is that because it's a function and to make a function intialize we have to always put a ()
@eternal needle Ah that pretty much explains it. Thanks

eternal needle
sturdy wharf
#

hey guys i have a weird glitch...

I have a simple unity project, and everything works good (as intended) in the editor. But when i build and run my project, the build version doesn't work, and when i go back to the editor after, it also breaks the editor in the same way. Ive searched online and found similar issues but all of their fixes havent worked. I've restarted unity, changed the execution order and a few other things i think. If you need more details please ask.

Thank you !

buoyant finch
#

hello I am making a 2d rpg and in it I have an npc who I want to follow a fixed path for 1 event another fixed path for another and so on pls guide me on that

summer shard
#

should i always split my scripts into sub folders like CoreMechanics, Managers etc?

sturdy wharf
wintry quarry
sturdy wharf
#

when i was recording the video suddenly it fixed 🙏 ive been trying to fix this for hours idk why it suddenly works. thanks hah

queen adder
#

guys why doesnt my pythong work

print('world hi')
if print = sigma
sigma
#

just kidding, haha!

worn flint
#

Question, what's better? VS code or just VS? I've heard some people say that they like one over another and I just don't know which one to use.

timber tide
#

VS code is very light weight but you do miss out on some features that VS has

teal viper
#

I wouldn't recommend vs code simply because a beginner is very likely gonna mess up it's setup and just gonna use it I configured without even knowing it.

timber tide
#

Right, I think last time I added code for a Unity project I needed to link the .net SDK and some directories, but other than that the Unity extension does probably do some of that heavy lifting

buoyant finch
#

hello I am making a 2d rpg and in it I have an npc who I want to follow a fixed path for 1 event another fixed path for another and so on pls guide me on that

timber tide
#

Otherwise you have Unity's Pathfinding module but that requires a lot of reading into the API

#

Oh, actually not sure if the module works for 2D, unless that was updated

languid spire
devout flume
#

You cannot modify an inbuilt component, you would need to have another strategy to indicate that state (either a custom script you put on each component, and you get it using GetComponent<>(), or a data structure like a dictionary)

#

Maybe there's another solution that I'm not aware of though

#

Oh this, maybe but I can't tell you unfortunately

languid spire
#

of course you can. something like this

Animator anim = someGameObject.GetComponent<Animator>();
anim.SetBool("Walking",true);
past spindle
#

When I try to assign an object to a public variable in my prefab's script, I get "type mismatch" in the inspector dropdown. I can drag & drop it, but the change won't apply to all when I try to override. Anybody have any ideas?

languid spire
#

you cannot assign objects from the hierarchy to prefabs

past spindle
#

I'll see if I can go about this a different way then. Thanks

mystic robin
past spindle
languid spire
ionic raven
ionic raven
#

I'll give DateTime a go in the morning

proven matrix
#

Hey guys. I have a game and I am tryna implement a Firing function. When the player press E they fire a gun. However, I have put the fire() method in the update function, is there to delay the fire method being called every frame because when i press E, loads of bullets come out

languid spire
summer shard
#

why can't i reference my method in unity event???

public void ShowDialogue(Dialogue dialogue) {} //this method


[Serializable]
public struct DialogueLine {
    public string person;
    public string text;

    public DialogueLine(string person, string text) {
        this.person = person;
        this.text = text;
    }
}

[Serializable]
public struct Dialogue {
    public int id;
    public List<DialogueLine> lines;

    public Dialogue(int id, List<DialogueLine> lines) {
        this.id = id;
        this.lines = lines;
    }

    public static bool operator ==(Dialogue c1, Dialogue c2) {
        return c1.Equals(c2);
    }

    public static bool operator !=(Dialogue c1, Dialogue c2) {
        return !c1.Equals(c2);
    }

    public override bool Equals(object obj) {...}

    public override int GetHashCode() {...}
}
proven matrix
#

private void PlayerInput(){ //Check if player is touching on the ground and if spacebar is pressed if(Input.GetKey(KeyCode.Space) && isGround){ Jump(); isGround = false; animator.SetBool("Jump", true); } }

languid spire
#

Ok, so go and read the docs and look at the difference between GetKey and GetKeyDown

proven matrix
#

Ahh

#

ill try implemetn that h

proven matrix
languid spire
#

what does the code you posted have to do with firing bullets?

proven matrix
#

Waitr

#

i sent the wrong one

#

lemme

#

void onFire(){
//If player press "E" attack animation will happen
if (Input.GetKey(KeyCode.E) && isGround){
animator.SetTrigger("Attack");
Instantiate(bullet, gun.position, transform.rotation);
}
}

#

This is the fire() method

#

I am sorry

languid spire
#

same problem

burnt vapor
proven matrix
#

Oh wait, that worked

burnt vapor
burnt vapor
#

It's a lot more readable and scalable

queen adder
#

is it possible to disable the rigidbody2d component or i have to delete it

#

wait no i just want to disabe hte gravity

timber tide
#

Pretty sure you can set enabled to false, otherwise setting it to kinematic should work

queen adder
#

oh i found it

#

its gravity scale

timber tide
#

That would just affect the gravity acting on the rigidbody, but if that's all you need

#

still prone to be affected by other forces and bodies

prime lodge
#

i have simple scene and i wanted to test something in play mode so i pressed the play button and its loading 7 minutes now

#

is it stuck or should i wait

#

or can i somehow exit the play mode

tidal quartz
#

hi, tbh im not really even a dev. i just make games with my friends from time to time using tutorial. I made a clicker using playerprefs to save data, and the value goes to negative when its over 2.1B , anyone know fix?

slender nymph
devout flume
#

Sounds like signed int capacity overflow

summer shard
#

is there a way to get text mesh pro text without the rich text, just pure text?

slender nymph
#

did you look at the TMP_Text docs?

burnt vapor
#

Generally you should also not use PlayerPrefs in general. Make your own system. The way PlayerPrefs work is generally frowned upon since it uses registery keys.

languid spire
full coral
# languid spire what is NiceIO

It's a file that support the code conversion of an apk. But now my more specific issue is my input system is holding onto my press input and never triggering a release. So if I click its counts as a hold per tick and I don't know if there's a way to redo the function or force unity to release it after a timer

#

I can show more specific documentation if I need

summer shard
slender nymph
#

then surely you didn't look hard enough

summer shard
slender nymph
#

sounds like the TMP_Text object you are calling that on has no text then

summer shard
#

hmm i'll try again thanks

summer shard
# slender nymph sounds like the TMP_Text object you are calling that on *has no text* then

im setting the text with dialogue.text = something and it seems to have a delay?

private IEnumerator displayDialogue(DialogueLine line) {
    string prefix = $"<b><color=#fff454>{line.person}:</color></b><br>";
    //Set the max visible characters to 0, set the text to the line and conjust the text

    dialogueText.text = $"{prefix}{line.text}";

    Debug.Log("passed line: " + line);
    Debug.Log("Normal text: " + dialogueText.text);
    Debug.Log("Parsed text: " + dialogueText.GetParsedText());

    yield break;
}
#

the parsed text is the text that's by default in game, like it's set in the scene

slender nymph
#

before i provide any other information, what is the actual purpose of parsing the text you are assigning?
https://xyproblem.info

summer shard
slender nymph
#

cool so you don't need that at all. just modify the maxVisibleCharacters property on the TMP_Text instead

#

and you've already got the text you need because you're literally creating the string from that text

summer shard
slender nymph
#

you have the unformatted text already

summer shard
#

where

slender nymph
#

in your line object obviously

#

you know, where you get the text that you wrap in your rich text tags

summer shard
#

it's split by text and person and it adds additional ":" character

#

and once i change the prefix i have to change everything

slender nymph
#

oh no, you have to get the length of two strings and add them together. that's so difficult

summer shard
#

did u not read what i've said

summer shard
slender nymph
#

what part of what you said means what i said cannot be done? you do realize that just adding those lengths together is going to be much better than always grabbing the parsed text, right?

summer shard
#

but i've wanted more reliable method of getting the unformatted string

summer shard
slender nymph
#

now explain how that changes anything about what i said

slender nymph
#

you have the string already. so just use its length. that's it. you don't need to get the parsed string because you already have it before you add the rich tags at all

summer shard
#

why can't i just get parsed string?

slender nymph
#

oh you can. and you can look up why it isn't working. i'm not going to help you further if you're going to be this fucking dense about what you are doing though.
because you're worrying about what happens when you decide to change the hard coded part of your string as if you wouldn't already know what number of characters you are adding to that hardcoded part of the string

#

it will always be more performant to just add the lengths of these strings together rather than calling GetParsedString which is going to allocate a new string each time

summer shard
devout flume
#

I'm a bit confused, you want the length of the final text without all the rich format, you make out a string which, without format, is {line.person}: {line.text}, the length is just 2 + length(line.person) + length(line.text) (length may not be a valid function, the idea is here)

slender nymph
#

but you see, they don't want to do that. they'd rather allocate a bunch of data instead of doing that

#

they also don't even need to use GetParsedText if all they are trying to do is get the character count

summer shard
slender nymph
#

it allocates an array and a string every time you call GetParsedText

#

and naturally, the longer your text is, the more data will be allocated. but you've already got the relevant data

summer shard
devout flume
summer shard
devout flume
#

In between the character (: ) or at some other places?

#

Realistically

summer shard
#

yea

devout flume
#

Then create a 3rd var

slender nymph
# summer shard and? it's not like it's gonna drop 20fps

this is clearly for dialogue. and if it is a dialogue heavy game you're going to be allocating a lot of memory doing this shit this way.
imagine causing so much garbage that your game starts stuttering just because you are too fucking arrogant to add some numbers together

summer shard
#

is it my problem that it won't delete the allocation right after?

slender nymph
#

you've also completely ignored the other relevant properties on the TMP_Text object which would have been better to use because you do not need to get the parsed string at all

slender nymph
devout flume
#

To me a dialog is realistically this: {username}{dialog separator}{dialog}, you could add the length of each and add all the rich text you want after

slender nymph
#

the more work that the GC does, the more stuttering you will experience

tall nest
#

can I use unity to make games on my PC?

timber tide
#

maybe

tall nest
#

Ok I will try when I become ready

#

I have 8gb ram

devout flume
#

Yes a garbage collector is a pain, it makes the work easier as you do not need to manage memory yourself (sort of) but you clearly lose in performance, as it will have to count every reference for every heap allocated variable in the code, which will take some CPU