#💻┃code-beginner

1 messages · Page 787 of 1

deft loom
#

ok ty ❤️

narrow spoke
#

I am instantiating shop buttons at runtime using Instantiate.
Icon, subtitle and price are set correctly, but the title (TextMeshProUGUI) is empty in the instantiated object, even though:

the title text is assigned correctly in the prefab

the TextMeshProUGUI reference is set in the script

titleText.text = title; is called

debug logs confirm the text value is being set

The title shows correctly in the prefab, but not in the instantiated clone.
I am using LayoutGroup / ContentSizeFitter in the UI hierarchy.

Why is the TextMeshPro text not rendered or invisible after instantiating the prefab, even though the value is set?

solar hill
#

and are you setting a reference at runtime or by assigning a prefab

narrow spoke
#

i found the misstake Insade of my Data where i store the diffrent buttons the can atteched i missed out giiving it a title waht cursed to have no title even when i was targeting a other title

narrow spoke
eager needle
#

Hey Guys, trying to achieve some sort of enemy attack here. The attack would be. laser coming out of the eye of my 2D enemy. so I atttached a linerenderer component and through code I am trying to make it appear when the player is at the right distance. because the laser stay attached to the eye of the enemy and go forward. But now I have an issue. again on Vector direction. I have my spawnLaser empty that is properly rotation (left arrow going left). but when I start to define the index 1 of the linerenderer it's going in the wrong direction.

frail hawk
#

is your lr not a child object of your player, it should rotate with him

eager needle
#

its a component attached to the ennemi. if it help. here is the function

#
    void ShootLaser()
    {
        float laserLength = 5f;
        Vector2 startPos = laserOrigin.transform.position;
        Vector2 endPos = startPos + Vector2.right * laserLength;

        laser.enabled = true;
        laser.SetPosition(0,startPos);
        laser.SetPosition(1,endPos);
            
#

The Vector2.right is probably the culprit. I am trying to get the direction of the red arrow

frail hawk
#

transform.right

eager needle
#

tried that but then I have an issue because the transform is a vector 3

#

so I am trying to add a vector 2 to a vector 3, it doesn't work

naive pawn
#

you can cast one to the other

eager needle
#

and based on the comment here it's in world space

naive pawn
#

the issue isn't because you can't do the operation, but because there's 2 things it could be and it's ambiguous

#

either you could convert the vector2 into a vector3 and then add them, or vice versa

#

so you need to explicitly cast to specify one

naive pawn
eager needle
#

it's not because I rotated 180degrees

#

the laser spawn position.

#

but maybe I am wrong on the concept here 😄

naive pawn
#

how is it turning around?

#

just flipping the sprite, or rotating/scaling the gameobject?

eager needle
#

I changed the vector 2 to vector 3 and put transform.right.

frail hawk
#

and just enable and disable the gameobject ,you dont have to draw it at runtime, when inspecting your code i dont see anything that you are chaning there

eager needle
#

here is the line renderer

#

it's going in worldspace to the right

naive pawn
eager needle
#

I could.

#

is it a good practice to have a character looking right by default?

frail hawk
#

yes

eager needle
#

I draw this turkey myself. but haven't thought about that

naive pawn
#

it sounds like your gameobject's "right" and your sprites visual "right" aren't the same

frail hawk
#

if you dont rotate the player but only flip the sprite you wont get the result you want

naive pawn
#

though, you could probably just use the laserOrigin's "right" to fix this for now. you should consider getting a more consistent system in the future though

past yarrow
#

Hey,
Is it possible to get the key of the found value (dictionary) please ?

eager needle
frail hawk
#

it is easy, you are only visually flipping your sprite. you have to rotate it

slender nymph
slender nymph
#

that doesn't show how you are using the dictionary, that is simply how you are defined it.
where you are using it is where you actually use the variable. you know, like this place where you are trying to get a key from a value even though values are not unique so more than one key could have the same value. there is no built in way to get a key from a value because that's not how dictionaries are supposed to be used

past yarrow
slender nymph
#

right so you are using it backwards

naive pawn
#

why are you trying to get a enum member from a color anyways

#

and why do you have [SerializeField] on that? you can't serialize a Dictionary

slender nymph
#

yeah this whole setup seems odd

past yarrow
# naive pawn why are you trying to get a enum member from a color anyways

I'm building a CLUE (CLUEDO) game and I'm using an image where each square is a pixel and each pixel has a color and when I retrieve a color from a pixel, depending on that color I can build my level design (So it's like a Level Editor) and I can assign a tile if it's a room (the enums) or a corridor, etc... and also some colors are player(s) spawn position.

I can serialize the dictionary with Odin plugin

naive pawn
#

yeah so why not just store the data in the tiles

#

using colors just sounds like a more obscure version of magic strings to me

past yarrow
naive pawn
#

you don't have to configure every tile individually, no?

#

can't you basically use tiles as prefabs

slender nymph
past yarrow
slender nymph
#

the image you just showed, how/where is it created

slender nymph
#

but why? that's objectively harder than just using a tilemap in unity or even Tiled since you're just using a bunch of squares

past yarrow
slender nymph
#

i didn't say "use a tilemap for the in-game map"

past yarrow
#

then I'm not sure to understand 🤔

slender nymph
#

i am referring only to this map mockup that you use to generate the actual map

#

you can create the mockup using a tilemap and then generate the actual map from that in the editor. and you can embed data in the tiles so that you aren't relying on sampling pixels to get their color

past yarrow
slender nymph
#

which part of that are you unsure about

past yarrow
#

like how to use a tilemap and mainly how to make each tile have data 🤔

slender nymph
#

how to use a tilemap
unity learn should theoretically have a tutorial about that, but even if it doesn't the manual documentation can teach you about it
how to make each tile have data
inherit from TileBase and put whatever fields you want on it. Congrats, you have your own type of tile with configurable data, then just create the instances of the tiles you would like for mocking your map and throw those into a tile palette

dusky beacon
#

hiii i need help

#

i made a movement script but it keeps telling me this

grand snow
#

!input

radiant voidBOT
# grand snow !input
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

grand snow
# dusky beacon

read the info above and the error message (that explains it too)

#

Input class is old input

dusky beacon
#

where r projest settings

rich adder
grand snow
#

Thats something you hopefully learn on day 0

dusky beacon
#

yeah im new new

#

i can 3d model but i wanna make a game

grand snow
#

!learn

radiant voidBOT
crude zephyr
#

Hello

dusky beacon
#

I DID IT

supple phoenix
#

Hello , if im trying to make 2D Rig should i make the rig in blender or unity.

grand snow
#

unity so you can use the unity 2d rig features

supple phoenix
#

ty

floral garden
#

hi, i have a question on how to make an effect of haze in 2D and i have not idea how to make it. I haven't find any tuto on it or don't know where to find it

normal mango
#

I'm currently working with UI elements and figuring how to drag them around. I'm noticing that I can't change the rect transform position during runtime, so do I have to be manipulating the pivot instead?

floral garden
#

do you mean moving them like windows ?

normal mango
#

windows?

floral garden
#

like app window

normal mango
#

nah, just prefabs

floral garden
#

what do you mean prefabs ?

normal mango
#

using the mouse position to drag them around

floral garden
#

in the folder ?

normal mango
#

its an instantiated prefab in the scene and im trying to move them around with the mouse via code during runtime

floral garden
#

i think you can

normal mango
#

i literally cant

floral garden
#

something like that you want to do ?

normal mango
#

i havent yet, ill check it out

floral garden
#

okk

normal mango
#

already doing what he has, and still not working

#

let me send the code

#

the final debug outputs the accurate new local position, but the actual object doesnt move, nor has its position values changed despite the console stating otherwise

floral garden
#

it is just a game object ? only with a rect transform ?

normal mango
#

rect transform and the scripts, but the other script shouldnt be affecting anything

floral garden
#

i think i am still to new to help debug it.

#

have you try to enable debug mode in the inspector to see if you get the right canvas and transform ?

#

otherwise another having more experience can help you haha

#

I am reitering my question if someone missed it.
how to make an effect of haze in 2D and i have not idea how to make it. I haven't find any tuto on it or don't know where to find it

normal mango
#

found the issue, it was infact the other script interfering lol

dusky beacon
#

does anyone have a WASD scrollable first to third person movement in unity??

#

script

#

ive been struggling to make one

rich adder
#

combine the first and third person controllers by unity

#

No one is gonna have a specific script for these things you need to learn building yourself

dusky beacon
#

thank you

rain solar
#

is there such thing as an algorithm that can be run on a marching cubes generated mesh to reduce vertices on flat faces?

fathom horizon
#

Yeah there is 👍

What you’re looking for is generally called mesh simplification / decimation, and it works well on marching-cubes meshes, especially for flat areas.

fair shore
#

I have a test code testing raycast in ui gameobjects that looks like this

    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit) && hit.collider == this)
            {
                Debug.Log("the gameobject" + this.gameObject.name + "have been hit");
            }
        }
    } ``` but the raycast did not work on the ui gameobjects, why? (the ui gameobject is not a button)
fathom horizon
#

inbox me

naive pawn
#

i don't think you'd want that though

slender nymph
fair shore
slender nymph
#

put an EventTrigger component on the object and it becomes fairly obvious

fair shore
#

ok thanks.

tired python
#

I want to add a range showing mechanism wherein if I click on a tower in a tower defense game, I will be able to see the range of the tower in a circle . I want it to be such that, in the future I will be able to increase and decrease the size of the area based on upgrades and stuff.

#

I figured that I could just change the scale of a sprite attached to it, is there a better way?

wintry dew
#

is there an easy way to match collider bounds with a non-uniformly scaled gameobject

#

because when i scale for example a cylinder in the x direction the collider takes up much more space than is visually shown

wicked cairn
wintry dew
#

well the issue is i want the collider to match the visual mesh continuously at runtime

wicked cairn
sinful zinc
#

how do u create a new material preset for a tmp text

#

in unity 6

modern meteor
#

what are the fundamentals that I should learn first in unity

#

I had experience with python before

radiant voidBOT
teal viper
#

Beginner pathways.

elfin birch
#

Hi

frail hawk
#

many people avoid using them but once you learn the basics of the particle system you will love them

#

!collab

radiant voidBOT
# frail hawk !collab

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

real thunder
#

I need a mob to decide what to do next and transition into new animator state after his attack animation ends (that mob have it's FSM running in Update outside of animator)
I only see two options:

A) I create Attack state transitions into all possible states (what a mess)
then I read a callback I get from OnStateExit to change it's internal FSM state

B) Attack state have no transitions out of it
then I get a callback from OnStateUpdate if stateInfo.normalizedTime == 1 and through code do a Animator.CrossFade inside internal FSM

So my questions:
Are there other better options? What is the way you d prefer?

Won't option B add one frame delay comapred to option A because of if I get it right A would instantly switch animation when it can and B would have to wait one frame? Can that be noticable? Can it be worked around?
If I think of it it can be worked around by tuning Crossfade normalizedTransitionTime and if it's too long outright doing Animator.Play for next animation

past yarrow
loud yarrow
sour fulcrum
past yarrow
undone wave
#

regarding Audio.PlayScheduled(), is there a specific recommended number of minimum time from now to the scheduled time, or is it mostly dependent on lag, etc?

#

for example, setting PlayScheduled to play at the curret time obviously causes latency, and setting it to play approx. 1 second later makes it fine, but would there be an 'ideal' minimum wait time, if i wanted to play the audio as fast as possible?

#

(experimentally obtained values are also fine, if someone has already tested this before)

past yarrow
#

Why doesn't my dictionnary show properly in the inspector ? Like why does it display "None" and it attributes the color of the attic to it and why there are only 9 elements instead of 10 ? 🤔 Like I just added None and Corridor to the enum and it messed everything up 🤦‍♂️

grand snow
#

Odin is what gives support to serialize dictionaries

grand snow
past yarrow
grand snow
#

Its normal

grand snow
past yarrow
grand snow
past yarrow
frosty hound
#

Not a coding question. Uses coding channel. 🤷‍♂️

#

You can remove packages from the package manager.

wintry dew
#

or a cylinder

swift crag
#

The collider uses the Transform of whatever object it's attached to

#

so if both the MeshRenderer and the MeshCollider are:

  • on the same object
  • using the same mesh

then they will match

#

In fact, they do a better job of matching the mesh than other collider types. If a parent transform has a non-uniform scale and you rotate the child object, the child gets skewed

#

but primitive colliders are not allowed to be skewed

#

(the entire point is that they are very easy to think about; they can't start bending and warping)

stone oar
#

how to prevent navmesh from generating inside enclosed meshes? like cubes for example. and merging/masking meshes won't work because im using blockbench for building levels.

wintry dew
swift crag
#

They’re less efficient, and they’re also a bit less reliable

swift crag
swift crag
wintry dew
#

that makes sense because you cant garuntee a volume if vertices go into the volume

swift crag
#

mesh colliders are allowed to have holes, intersecting faces, etc.

#

so there's no coherent way to define "inside" at all

zenith cypress
swift crag
#

it's remarkably annoying!

stone oar
swift crag
#

iirc you defined a set of "known-good" points and tried to navigate to them from every navmesh triangle

swift crag
#

minecraft just cares about the block under the mob that's trying to spawn

stone oar
stone oar
#

sob..

swift crag
#

one thing you can do is test if the mob can reach the player before you try to spawn it

#

just query the navmesh and see if it finds a path

#

this could get expensive if you want to try to spawn many mobs, though

zenith cypress
#

That also can give false positives LMAOO

swift crag
#

computer hard

stone oar
zenith cypress
#

A lot of paths result in a "partial" result, which can be from "can probably reach you through this gap" to "can't actually reach you because this property is too generalized"

#

I can probably show what mine does, although it will contain my game-specific stuff but you can probably see what it does and understand an approach that works for you.

stone oar
#

thought "well a real game engine would definitely allow me to spawn 1 quadrillion enemies at the same time thinksmart "

stone oar
#

my main idea is to allow random enemy spawn locations inside of a room

zenith cypress
#

That's what my game does too yeah

stone oar
#

i have yet to determine whether i want to store rooms as disabled objects or load them all at once (probably first one)

#

though the code rn just instantiates new prefabs which i learnt is perfomance heavy. ah yeah perfomance, a nightmare on its own

zenith cypress
stone oar
zenith cypress
#

Interior/invalid location exclusion

stone oar
#

well thanks for sharing it

#

based on the channel we are in - you can assume that i won't be able to use it nor understand how it works

#

so ig ill just try raycasting upwards to see if there is a ceiling in place and deal with that

solar hill
solar hill
#

from what i see they build the NavMesh twice.
First to get all triangles then it tests which ones are unreachable from valid points (doors, spawns, anchors)

#

and then overlays those with an "unwalkable" mesh before rebuilding effectively carving out isolated areas.

#

its a pretty nifty way of doing it

stone oar
#

but they are not selectable in editor

solar hill
#

they are doing it through code.

#

its all in the code like i said

#

its pretty understandable you just have to read through it carefully

#

they use a for loop to test the triangles

stone oar
#

but i wont understand

#

skill issue on my part, like i said

#

i barely understand what any of the methods used do because i never used them

solar hill
#

the unity api is public, you can always look them up

#

its a good way to learn

#

analyzing other peoples code and understanding how it works

stone oar
#

its easier when i know what it should do, otherwise - it just looks like magic to me

slender nymph
#

!collab 👇

radiant voidBOT
# slender nymph !collab 👇

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

naive pawn
#

<@&502884371011731486> scam/spam

solar hill
#

they also post about their artstations and what not

zenith cypress
stone oar
solar hill
#

what do you mean missing and or unknown?

stone oar
#

as an example

slim solar
solar hill
#

and whats wrong with it? getComponentsInChildren is a function...

slim solar
#

I had the same issue and just plopped those zones around, worked perfectly

stone oar
#

maybe i dont know how to put them correctly

slender nymph
slim solar
#

Obstacle just reduces the chance agents will use that area, like a fire or a box they climb

#

Modifier will prevent navmesh

stone oar
slim solar
#

Yeah, keep it simple for now, try navmesh modifier and adjust the values on it if needed

tired python
stone oar
slender nymph
slender nymph
#

so you understand that it is purely an example of the logic you should use, yet you're still trying to use it as a drop in solution?

zenith cypress
#

Yeah it was an example of how to do it for rooms that are more "dynamic" (for my case they are made in Trenchbroom with zero unity authoring hence the need for it to work)

stone oar
#

i understand the concept but its a bit out of my scope unfortunately. maybe in the future ill have enough experience to actually make something like that

zenith cypress
#

If you are able to just author stuff on top of your rooms in the editor, then you probably don't need it and can just place your own blockers around (just requires more manual labor)

stone oar
slender nymph
#

then read through the logic that is actually there, and ignore the stuff that calls methods on types you don't have because that is likely not related to the logic you need

slim solar
slender nymph
#

it is against server rules to answer questions with unverified ai generated content

hot wadi
#

Well they could have just copy and modify the font to make it look like man-made. The real problem here is double checking

stone oar
#

ai hallucinates most of the time

slim solar
#

Err its a very simple thing lol. Let me rephrase

#

Add navmesh modifier component to any mesh/zone and set it to override. Rebuild navmesh. Done

#

I just didnt remember the correct naming

stone oar
#

me, when my room is just one model: notlikethis

solar hill
#

ask your ai it might tell you 😉

slim solar
slim solar
#

I dont understand why everyone is acting like this extremely basic feature doesnt exist or is an ai hallucination?

stone oar
#

life, if unity prefabs allowed storing navmesh: uwu

slim solar
#

They allow storing the overrides

#

Anyway i solved this very easily in multiple game releases, so goodluck with the overengineering I guess.

stone oar
#

that can work

blissful stratus
#

how can i make the player squeeze when moving?

solar hill
#

didnt you already ask this?

#

and i asked you to clarify

#

and you said nothing UnityChanHuh

blissful stratus
swift crag
solar hill
#

bro forgot

blissful stratus
solar hill
#

so yes squash and stretch

#

but we need more context

#

is this a 3d project or 2d?

blissful stratus
solar hill
#

so im assuming your character is a sprite?

#

i would use tweening for that

blissful stratus
solar hill
#

for you that means you get to animate your characters scale

#

to make them stretch

blissful stratus
#

oh you mean the asset

solar hill
#

tweening is just a general concept.

#

there are many libraries you can use for it

#

the most popular one being dotween

#

but theres also leantween

swift crag
#

Libraries like DOTween make it really easy to do these kinds of effects.

#

When you dash, you'll briefly change the scale of your character

blissful stratus
#

if i scaled the x or y value it might break my character logic

swift crag
#

consider setting up your character like this

  • Player <-- the collider and other scripts
    • Visual <-- the SpriteRenderer
#

this lets you move/rotate/scale the visual without affecting anything else

mild reef
#

how would I make this check all of the objects in the array all together instead of one at a time. it seems like the else statement is just changing the bool back immediately for each one of the game objects.

ivory bobcat
teal viper
teal viper
ivory bobcat
mild reef
#

just trying to make it so the else isnt just instantly covering it up by something else in the array

mild reef
ivory bobcat
#

!code

radiant voidBOT
teal viper
slender nymph
radiant voidBOT
teal viper
ivory bobcat
#

This is very likely an x/y problem where you're getting a behavior that isn't wanted because of something else.

teal viper
#

No, it's clearly a logic issue. They want to set the bool to true if any of the objects in the array are inactive.

teal viper
#

But yeah, configure your ide as well if you need further help.

mild reef
polar acorn
#

Whatever the last object is, that's what gun.shootingbuttonenabled is

mild reef
#

well yeah.... thats why I asked for help

polar acorn
#

So what do you want to happen

mild reef
#

all together I mean

polar acorn
#

There is no "all at once" in programming. Code runs one line at a time. You'll need to rephrase your thinking. What should it be by default, and under what conditions should that change?

wintry dew
#

anybody know a simple way to draw a rectangle to the screen with given vertices in screen coordinates or something analogous with world coordinate projections?

mild reef
#

thats why I had the else, with the idea that at the end of checking everything it would change based on that. not sure how to go about that

polar acorn
mild reef
#

any suggestions on what I could do to do it at the end of the whole array?

polar acorn
#

Pick a default state, then look for whatever condition makes it be the other, and check for that

#

"gun.shootingbuttonenabled should be true unless _____" or "gun.shootingbuttonenabled should be false unless _____"

#

fill in the blank, then check for that

teal viper
mild reef
#

so if I just did an if statement right below with the opposite it should work? just another obj.activeself == true

teal viper
#
bool = true
Loop
{
 if condition is right
 {
   bool = false
   break out of the loop
 } 
}
mild reef
#

ah ok

polar acorn
#

So, pick one to start at, and only change it if you need to

mild reef
#

but I do need to change it

teal viper
polar acorn
ivory bobcat
#

Are you wanting the state to be true if any of the objects were not active?

mild reef
polar acorn
#

You don't re-set it back to true ever

#

Just once at the start

#

and set it to false if it should be false

mild reef
#

i meannn this wont work tho right

#

same thing?

ivory bobcat
#
shoot = true
foreach ...
    if ...
        ... = false
        break;```
teal viper
# mild reef

Obviously the break needs to be in the if block

mild reef
#

hahaha mb

polar acorn
# mild reef

Think through that in your head. Step through it, line by line.

#

Let's say you have a list containing, in order, an inactive object, an active one, then an inactive one

#

What does your code do in that case?

floral garden
#

couldn't we break without the bool at start ?

#

what the issue? how to find the first active object in the list ? ( maybe i missed something)

mild reef
#

this is my sloppy solution. ill lyk when it breaks guys. thanks for the help

floral garden
#

why this much space ?

mild reef
#

ive been avoiding arrays for 4 years so this all really helps

mild reef
ivory bobcat
polar acorn
mild reef
#

bro it works

polar acorn
#

No, you just havent encountered a situation that breaks it yet

mild reef
#

so it works

#

bandaid fix

floral garden
#

no

teal viper
#

This is a pretty messy solution. I literally gave you the pseudocode that solves the issue neatly...

#

Why didn't you just implement it?

floral garden
#

it work for only a specifique stuation

polar acorn
mild reef
#

yes

polar acorn
#

Then tell us

#

What does this code do

mild reef
#

but it works because I wont ever have two objects turning off and on with that script involved

floral garden
#

what ?

teal viper
polar acorn
mild reef
# polar acorn What does this code do

it goes through the array and checks if an object is active. depending on the result of each object, itll save the object into consideration for later to wait for it to be false technically

polar acorn
#

It will store the first active object

#

Then, if that active object is inactive it'll set the bool to false

#

An active object of course cannot be inactive

#

So what is the point of checking if the object you just confirmed is active is inactive

mild reef
polar acorn
#

And then it will make sense

#

Either blank

#

One of them will be easier than the other but both work

mild reef
#

but isnt that the whole point of this script and the loop?

#

are you suggesting I make it true before the loop in the update?

floral garden
#

there a 2 ways to do it

polar acorn
#

Considering that at this point like six people have told you exactly that, yes

#

Or the opposite, whatever's easier

floral garden
#

i like give answer but if that person don't understand it is better he find the anwser himself

What i get is you have a gun , with a list of gameobject (for what , idk)
each update (not the best idea but well)
you check if you have an actif object in the list, if yes then you can't shoot but otherwise, you can shoot ?

mild reef
#

just like this?

polar acorn
#

Set it one way. Do the loop. If you find a condition that means it should be the other way, change it

floral garden
ivory bobcat
floral garden
#

oh miss the break

polar acorn
mild reef
#

lol

floral garden
#

but the ideas is same

mild reef
#

same thing yeah?

#

mmm thanks guys, makes sense now

floral garden
slender nymph
#

break will not make the code after the loop not run, in fact it will immediately go to that code. so that // turn gun on bit is what will run immediately after the // turn gun off part

floral garden
#

haha

#

turn gun on should be upper

mild reef
#

so the break would start it over before it turned the gun back on?

#

and not work is what hes saying

slender nymph
#

what? that is not what i said at all. break doesn't start anything over

polar acorn
floral garden
mild reef
#

so it wouldnt run whats below it in the update?

polar acorn
#

That is all it does

slender nymph
floral garden
#

like the words mean , your loop is a list of function doing almost the same thing then you break in middle

polar acorn
#

It ends the for each

ivory bobcat
#

It doesn't do anything else

mild reef
#

I see

floral garden
#

btw, switch for you is a loop or not ?

#

for me it a loop but maybe it isn't

slender nymph
ivory bobcat
floral garden
wintry dew
#

Does anyone know how i can perhaps project a sphere in world coordinates onto screen space coordinates

ivory bobcat
wintry dew
#

oh i mean like get from a sphere in world space to having a circle in screen space with a center and radius and stuff

mild reef
# slender nymph !IDE 👇 you need to get your IDE configured

also ive been trying to set it up, I just downloaded a more recent version of visual studio and its connected under prefrences in unity but now my variables arent suggesting. I also made sure to have the unity game development thing on visual studio too. not sure whats missing

slender nymph
mild reef
#

thanks

narrow spoke
#

Hey 🙂 I just wanted to make a Panel but it takes opver everything, why? and how can i fix it

slender nymph
#

this is a code channel. also, with it being a UI object, it lives on the canvas which is why it appears gigantic in the scene view, but normal size in the game.

#

read the documentation pinned in #📲┃ui-ux to learn how the canvas and UI work

wintry dew
#

Is there any easy way to detect if a world space object is within some screen space bounds?

#

Google has currently been failing me for a half hour now...

rich adder
#

break down the problem further so you can find more

narrow spoke
slender nymph
#

it generally helps to actually explain what your issue is

#

and in the right channel

ivory bobcat
rich adder
#

ahh the classic I have issue plz help, proceeds not to describe the issue

narrow spoke
#

I imported a big map image (1920×1080) directly into the scene. Now when I add UI (Canvas/Text), everything feels off scale-wise.
The map is already scaled down a lot, and if I scale it more, the aspect ratios start breaking.

What’s the right way to handle this?
Should I resize the map via PPU instead of transform scale, or is this more of a camera / canvas setup issue?

slender nymph
#

this is a "you didn't actually read and understand the information about how the canvas works" issue

narrow spoke
#

Sry 🙂

teal viper
mild reef
# mild reef just like this?

I've got a question on this. It does work. But I've confused myself. Why doesn't it just always read that the shooting button is enabled? Because if it goes down the lines of code wouldn't it set it to true again before making it false?

#

Like does it keep on changing it every 0.00001th of a second. I'm just trying to understand it more

#

Since every update its made true

teal viper
mild reef
#

So what your saying is that the "set to true" part of it doesn't actually go through until the end of the update or frame?

teal viper
#

No, it applies immediately, but it doesn't matter. Because if the condition is met, then false is assigned immediately after that.

mild reef
#

Mmmm ok

#

But then if it starts over again wouldn't it be 50/50?

ivory bobcat
teal viper
ivory bobcat
mild reef
#

It looks good. It does work. I just keep on trying to understand it. Like I get that it works like that. But I also just think it would be split 50/50 true and false. Simply because I have something always saying it's true on that update, but then something checking on that same update and changing it right after. But if it's changed that quick, wouldn't it also be changed back to true just as quick?

#

Just trying to make it make sense

#

For now it works and all I can say is "it's just unity" it's not wrong. But the timing doesn't make sense

slender nymph
#

keep in mind that nothing else is happening between the variable being set to true and it being set to false, but pretty much the rest of your game is happening outside of that update method

#

so basically it's true for "no time at all" on frames that it should be false, and will remain false until the next frame so the remainder of the frame it is still false. then the next frame, the exact same thing happens. until a frame where the loop never sets it to false

mild reef
#

Interesting

#

Definitely trippy

ivory bobcat
teal viper
# mild reef Definitely trippy

Nothing trippy here. You pc executes code line by line. No code at all runs while this script update is executed(let's ignore threads for now) . So for the rest of the game, it's either the value before it's update or after.

mild reef
#

So is nothing updated until the "end" of the update? Which would still be super small anyways

teal viper
#

Yes.

mild reef
#

Ah ok that makes sense

#

Thanks yall

slender nymph
#

that's still not quite it. the variable is changing. as has been said before.
but nothing else is checking the variable during this time because only one component is updated at a time

ivory bobcat
polar acorn
# mild reef

Only one line of code is ever running at a time. There are no lines of code between setting it to true and setting it to false that use the value. So, nothing will ever read the value as true before it has the chance to get set to false.

mild reef
#

There that's it that makes sense

ivory bobcat
#

The entire Update method has to finish before anything or anyone else can do anything (rendering to the screen, physics etc)

mild reef
#

Mmm ok

prime goblet
#

hello, i'm having a bit of trouble with my raycasts as they dont seem to be detecting stuff properly
this is what i've tried:

    void Start() {
        data = rock.GetComponent<RockTypeLinker>().data;
        
        rocks.Add(rock);
        
        for (var i = 0; i < data.iterations; i++) {
            currentRocks = new List<GameObject>(rocks);

            foreach (var useRock in currentRocks) {
                var testUnityIgnore = false;
                // right x
                if (!Physics.Raycast(useRock.transform.position, useRock.transform.right, out var hit, 1f)) {
                    var newRock = Instantiate(rock);
                    newRock.transform.position = new Vector3(useRock.transform.position.x + useRock.transform.localScale.x, useRock.transform.position.y, useRock.transform.position.z);
                    rocks.Add(newRock);
                }
            }
        }
    }

basically what i want to happen is
iteration one: no cube detected so it creates one
iteration two: cube deteced, no cube is created
...

but what's happening is:
iteration one: no cube detected so it creates one
iteration two: no cube detected so it creates one
...

I've tested in other scripts and the cubes can detect each other just fine.

#

this is the result (looks expected) but actually there's cubes inside cubes

tired python
#

when I drag a unit, since the unit has two colliders one it's parent gameobject and child gameobject, I end up dragging the gameobject when my mouse is on the child collider. I want it o be such that I only drag it when it's on the parents collider.

#
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;

public class UnitRelocatorScript : MonoBehaviour, IDragHandler
{
    // Start is called once before the first execution of Update after the MonoBehaviour is created
    Vector3 mouse_pos;
    private Collider2D _collider;

    void Start()
    {
        _collider = this.GetComponent<BoxCollider2D>();
    }

    // Update is called once per frame
    void Update()
    {
        mouse_pos = Camera.main.ScreenToWorldPoint(Mouse.current.position.value);
    }

    public void OnClick()
    {
        Debug.Log("Object was clicked.");
    }

    public void OnDrag(PointerEventData eventData)
    {        
        //6 = tower layer
        if (_collider == eventData.pointerDrag.gameObject.GetComponent<BoxCollider2D>())
        {
            gameObject.transform.position = new Vector3(mouse_pos.x, mouse_pos.y, 0);
            Debug.Log("Object is being dragged.");            
        }
    }
}
prime goblet
#

i have tried 1 sec ill get the screenshot

ivory bobcat
#

It might not be where you're thinking it is, how long you're thinking it is or something else

jolly jackal
#

hello, i'm having a bit of trouble with my raycasts as they dont seem to be detecting stuff properly
this is what i've tried:

    void Start() {
        data = rock.GetComponent<RockTypeLinker>().data;
        
        rocks.Add(rock);
        
        for (var i = 0; i < data.iterations; i++) {
            currentRocks = new List<GameObject>(rocks);

            foreach (var useRock in currentRocks) {
                var testUnityIgnore = false;
                // right x
                if (!Physics.Raycast(useRock.transform.position, useRock.transform.right, out var hit, 1f)) {
                    var newRock = Instantiate(rock);
                    newRock.transform.position = new Vector3(useRock.transform.position.x + useRock.transform.localScale.x, useRock.transform.position.y, useRock.transform.position.z);
                    rocks.Add(newRock);
                }
            }
        }
    }

basically what i want to happen is
iteration one: no cube detected so it creates one
iteration two: cube deteced, no cube is created
...

but what's happening is:
iteration one: no cube detected so it creates one
iteration two: no cube detected so it creates one
...

I've tested in other scripts and the cubes can detect each other just fine.

prime goblet
#

you just pasted my thing?

prime goblet
#

when I print the value of hit (assuming not null) it prints nothing

#

so the raycast specifically in this script detects nothing

#

but when run from another script it detects just fine

ivory bobcat
prime goblet
#

i tried with no limit and a really big limit, still didnt work

ivory bobcat
#

The max distance seems to be one relative to your code

prime goblet
#

the scale of my cube is 0.5,0.5,0.5 so 1f isn't short

#

especially since they're next to each other

#

but i have tried with no maxDistance and a really big maxDistance

#

made no difference

ivory bobcat
#

Can you show the raycast debug drawn?

patent vault
#

hello guyz

ivory bobcat
#

Do the objects have colliders?

prime goblet
prime goblet
#

and i tested in another script it seems to have nothing to do with them being kinematic or anything wrong with their colliders

ivory bobcat
#

So.. how many rocks do you start with? Is this Start method in every rock?

prime goblet
#

1 rock

#

this start method is not in every rock

#

it's in a seperate gameobject

ivory bobcat
#

What is currentRocks?

prime goblet
#

to prevent it from adding to the list it's currently iterating through i created a second list that isnt affected at the same time

#

whole snippet

using System;
using System.Collections.Generic;
using UnityEngine;

public class RockExpansion : MonoBehaviour {
    [SerializeField] private GameObject rock;
    private RockObject data;

    private List<GameObject> rocks;
    private List<GameObject> currentRocks;

    private void Awake() {
        rocks = new List<GameObject>();
    }

    void Start() {
        data = rock.GetComponent<RockTypeLinker>().data;
        
        rocks.Add(rock);
        
        // create rocks whenever it cant detect something is there with a raycast
        for (var i = 0; i < data.iterations; i++) {
            currentRocks = new List<GameObject>(rocks);

            foreach (var useRock in currentRocks) {
                var testUnityIgnore = false;
                // right x
                if (!Physics.Raycast(useRock.transform.position, useRock.transform.right, out var hit, 1f)) {
                    var newRock = Instantiate(rock);
                    newRock.transform.position = new Vector3(useRock.transform.position.x + useRock.transform.localScale.x, useRock.transform.position.y, useRock.transform.position.z);
                    rocks.Add(newRock);
                }
                
                // left -x
                
                // front z
                
                // back -z
                
                // top y
            }
        }
    }

    private void OnDrawGizmos() {
        Gizmos.color = new Color(0,0,255);
        foreach (var roc in rocks) {
            Gizmos.DrawRay(roc.transform.position, rock.transform.right);
        }
    }
}
ivory bobcat
prime goblet
#

in the raycast part

#
                if (!Physics.Raycast(useRock.transform.position, useRock.transform.right, out var hit, 1f)) {
                    var newRock = Instantiate(rock);
                    newRock.transform.position = new Vector3(useRock.transform.position.x + useRock.transform.localScale.x, useRock.transform.position.y, useRock.transform.position.z);
                    rocks.Add(newRock);
                }
#

that's where my issue lies

#

it's creating cubes even if something is already there

ivory bobcat
#

How are you continuing to create more rocks (assuming this script isn't on the rock object)

prime goblet
#

in that same code there's a for loop and a foreach loop.

#

the for loop, i want it to run 3 times so that there's a good amoutn of cubes
the foreach loop is to create cubes around it (but i havent added that yet) so instead of hard tracking locations and positions and cubes im only making sure nothing's there and thne just going for creaintg it

#

this is the first part but it seems to be failing

ivory bobcat
#

You've said that you start with a single rock and that the rocks are not running this code. My assumption is that there isn't anything wrong with the above but that whatever (some manager) is the issue.

prime goblet
#

i dont see how something would be wrong with the manager

#

it's an empty gameobject at 0,0,0 with that script on i

#

and at no point have i accessed the raw transform without it being either rock or useRock

ivory bobcat
#

If you're doing this all instantaneously, the colliders will not have been updated until a sync has occurred

prime goblet
#

i see, it probably is instantaneous

ivory bobcat
#

Thus each and every ray cast would not detect any object where an object might be

#

You can use a physics sync after creating the rock if you're wanting this all to occur instantaneously

prime goblet
#

alright, i'll check that out

#

thank you!

#

if that fails i'll just add a manual delay

#

that did fix it

ivory bobcat
prime goblet
#

alright

#

thanks

prime goblet
#

on what object is this script?

#

if it's on the parent then your gameObject.transform stuff will affect the parent

tired python
prime goblet
#

try putting it on the child or accessing the child's gameObejct instead

ivory bobcat
prime goblet
#

you could also check what pointerDrag actually is

tired python
#

the gameObject is this:

  • Parent:
    • Has collider and if mouse is dragged, while on this collider, parent should move.
  • Child:
    • Has collider on it and should not be moved when mouse is dragged while on this collider.
#

i have attached this script to the parent

prime goblet
#

this part will only run on the parent

gameObject.transform.position = new Vector3(mouse_pos.x, mouse_pos.y, 0);

because gameObject like that just accesses the gameObject that the script is on

#

you should instead be running the pointerDrag.transform.position or something like that

tired python
#

i want to move both the parent and the child at the same time

prime goblet
#

isn't that what you have?

prime goblet
tired python
prime goblet
#

so the child is not supposed to be draggable?

tired python
#

but its not happenning, instead, when i click and drag on the child collider, the whole thing gets dragged (parent and the child)

prime goblet
tired python
ivory bobcat
tired python
prime goblet
#

nothing moves?

#

that was never stated before

#

before you said everything moved

#

unless that's the outcome you want?

tired python
#

yes

prime goblet
#

oh

#

dragging the child should not move anything?

tired python
#

but everything moves right now, doesn't matter which collider i am dragging

prime goblet
#

oh okay

tired python
prime goblet
#

can you check which object pointerDrag is?

tired python
prime goblet
#

no like

#

in code

#

Debug.Log(eventData.pointerDrag)

#

i would imagine your function looking like this

public void OnDrag(PointerEventData eventData)
{        
    //6 = tower layer
    if (_collider == eventData.pointerDrag.gameObject.GetComponent<BoxCollider2D>())
    {
        Debug.Log(eventData.pointerDrag.gameObject);
        if (eventData.pointerPressRaycast.gameObject != gameObject) { return; } // if the object IS NOT the parent (which is the object with the script) then do NOT drag
        gameObject.transform.position = new Vector3(mouse_pos.x, mouse_pos.y, 0);
        Debug.Log("Object is being dragged.");            
    }
}
tired python
#

sry its taking a lot of time potato pc

prime goblet
#

haha take your time

#

also i think part of the issue could be the parent's hitbox being above the child's

#

based on your image

tired python
#

its on the parent

prime goblet
#

both have hitboxes?

#

if the parent covers the child then the child cant be dragged, ooonly the parent

tired python
prime goblet
#

is the child the big one or the small one

tired python
#

big

prime goblet
#

okay

#

then ignore that should eb fine

tired python
# tired python its on the parent
Pointer drag is on Droplet(Clone) (UnitRelocatorScript) object.
UnityEngine.Debug:Log (object)
UnitRelocatorScript:Start () (at Assets/Scripts/Unit Relocation/UnitRelocatorScript.cs:13)
#

it is on the parent, not the child i guess

prime goblet
#

when you tried dragging on the child did it show Droplet (Clone)

tired python
#

yes

prime goblet
#

that must mean your child's collider is covering the parent's collider

tired python
#

yes

prime goblet
#

maybe try going innto 3d view and move your child back behind it on the z axis

tired python
#

wait no

prime goblet
#

if the bigger collider is on top of the smaller collider and preventing the smaller collider from being pressed then maybe try move the bigger collider back on the z axis

tired python
#

that's not the problem

prime goblet
#

oh

prime goblet
#

oh right htat wanst hte issue

#

mb

tired python
#

ya

#

visuals always help

prime goblet
#

true

#

okay so when you printed it it acknowledged that you were dragging the parent?

#

even when you tried dragging the child?

tired python
#

wait

#

yes

prime goblet
#

okay

tired python
#

i could just make the BoxCollider2D a child and then put the script on that child

prime goblet
#

maybe try

#

im honestly not sure though, sorry

tired python
#

it's kinda working, the unit does get dragged the correct way at first, but the moment i try to drag it a second time, the event doesn't even get called

#

gamebar recording it dumb so there's a vertical offset, so even though i know i am clicking on the object, it appears as if i ain't clicking on the object

#

something i noticed was that in the Scene, if i change the collider a bit, then the next time i try to drag it on the game screen it does get dragged but then it becomes undraggable unless i change the collider in the game scene again

#

kill me pls, these bugs are so bloody hard to notice

#

i don't even know why i got the idea that the box colliders being on the same z axis somehow broke the thing, but apparently it's what was happening

#

the hell man?

cosmic dagger
#

you can't use the null-conditional operator (?.) with Unity objects . . .

past yarrow
#

Is it possible to have a single material that has a Color parameter that I can change through code and without having that same material applied to other GameObjects also change their color ?

By that I mean if it's possible to create a single material and I need to spawn alot of tiles and each tile will have different color, so modifying the color of a certain tile shouldn't change the colors of the other tiles and without me having to create 1 material per color that I want to use.

prime goblet
#

it's Renderer.material.color

past yarrow
prime goblet
#

can you record or show what hpapens when you try to use this?

hot wadi
prime goblet
past yarrow
prime goblet
#

ah okay

past yarrow
prime goblet
#

nice!

past yarrow
#

Why does it tell me it's redundant check ? 🤔

sour fulcrum
#

What makes you think it's not

hot wadi
polar acorn
#

What is the difference between this code and one that doesn't have it

past yarrow
polar acorn
#

The variable is that value either way

#

There is not a single difference between the code with the if and without

past yarrow
#

micro-optimization I guess 😄 Does that optimize something or it changes nothing ? 😄

polar acorn
#

Optimizing what?

past yarrow
#

assignation of value

hot wadi
#

No

polar acorn
#

You can't get any faster than zero time

past yarrow
#

no way assignation takes 0 time 😮

polar acorn
#

All it does is assign a name to a point in memory. The name is the same, the pointer is the same

#

Why would that take any time?

past yarrow
#

well each action a computer does technically take some time (milliseconds or microseconds but it's still time), isn't it ? Like lookin for that point in memory then assigning a name to it can't be free of time, isn't it ?

polar acorn
hot wadi
#

U are worrying about something that probably takes trillion or more of them at the same time to start affecting the system

past yarrow
past yarrow
zenith cypress
#

If anything the comparison is slower since you now need some redundant ldarg instructions to do the comparison (even in release mode so the compiler doesn't optimize it it seems). But for this is doesn't really matter, only thing that does is the takeaway of why it isn't needed in this case.

polar acorn
charred bear
#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Program : MonoBehaviour
{
publicTransform vehicleTransform;
Vector3 dir;

private void Update()
{
    dir.Z = vehicleTransform.eulerAngles.y;
    transform.localEulerAngles = dir;
}

}

#

would this work for a magnetic fluid compass inside an aircraft cockpit?

#

if the compass is just a cylinder with a compass texture and its origin faces front

#

also how would i go about writing a script for textmeshpro to read the title of an mp3 file playing through an in-game media player

eternal needle
charred bear
eternal needle
charred bear
#

what other kinds of angle conversions are there?

#

just because eulers seemed like the match for aviation related orientation

eternal needle
charred bear
#

or as far as i understand is able to rotate on all axes

eternal needle
# charred bear it's an airplane so it does rotate...

then maybe you'd want to construct a quaternion based on the forward direction of the plane. Really im not sure what the intent is here or why you set the localEulerAngles so it's hard to give a complete answer

charred bear
#

hold on let me show you a picture of the kind of compass

#

it spins on one axis in relation to how much the aircraft deviates from the north on a Z axis (aka aircraft heading)

#

there's an in-game heading indicator already but it isn't analogue like this one

#

i should've probably thought about checking the kind of angles it uses before i left home...

eternal needle
# charred bear

first thing id think of would be using the forward direction of the plane, set Y to 0 because you dont care if its pointed up or down right?
Compare that vector to like vector3.forward to get the angle to set the Z value of this object

charred bear
#

Would I still change my code how you suggested?

eternal needle
charred bear
#

Well at least it’s understood as eulers by the indicator? I’m not sure how it’s possible

keen dew
#

It's not a good idea to ask code questions when you don't have access to the project. But basically to keep the compass always pointing north this should do it:

Vector3 direction = Vector3.ProjectOnPlane(north, aircraft.transform.up);
transform.rotation = Quaternion.LookRotation(direction, aircraft.transform.up);

where north is the direction where you want it to point in world coordinates (e.g. Vector3.forward) and aircraft is a reference to the airplane object

charred bear
eternal needle
#

you can think of it using euler angles, you can set it using euler angles, its stored as a quaternion

charred bear
#

Oh okay

#

So even if the math will use eulers no matter what I want it to reference the quaternions instead

keen dew
#

It doesn't matter what you use, Unity will end up using quaternions anyway

#

the conversion is automatic

charred bear
#

Ohhhhh

eternal needle
#

you can fully keep track of everything using eulers stored as your own values, thats no problem

charred bear
#

I guess I’ll have to watch a video for how eulers work in unity and maybe read up on linear algebra

charred bear
#

I’ll give it another try tomorrrow then

#

Thank you

wild cove
#

Hey i've been trying to figure out how to run an if statement once in Unity and im just really confused how to stop the if statement after it runs once, because everytime I play test, when the player activates the function to spawn a new level it spawns infinite levels and crashes.

ivory bobcat
blissful mulch
#

could anyone explain how i can get a normal map to work or whatever its called? The thing that makes a material look more 3d

sour fulcrum
#

your using whats called a local variable, it exists exclusively in the context of when that function runs

#

and it's not doing anything either

#

like so your 100% clear these 4 lines (plus the bracket) are the only things doing anything

ivory bobcat
wild cove
#

and I dont think it could be due to anything else

wild cove
frail hawk
ivory bobcat
#

That trigger message is occurring multiple times. You've got to figure out why

sour fulcrum
wild cove
#

I gotta fix that rq

frail hawk
#

allright then if you want that code inside the Update you would simply use your "hasRun" boolean in the if statement too

#

so the condition is only met when your bool is false

wild cove
ivory bobcat
ivory bobcat
wild cove
# ivory bobcat So, the trigger enter message only occurs once (on initial trigger entered). Are...

I'm trying to make a simple infinite runner and if the player walks a small distance from a cube in the starting level it creates a new level, but my mistake is that I can't find a way to tell it to stop the if statement. It just keeps running the statement over and over because the condition is always met. The player doesn't teleport at all, it's just infinite levels are being created way too fast, and I need a way to stop the if statement from activating (even when the condition is met) once it runs once.

frail hawk
#

and i already told you how to do that

wild cove
#

Im sorry im really a beginner and im confused

#

I need to reread everything again

sour fulcrum
frail hawk
#

if ( condition1 && !hasRun)
{
some code;
hasRun = true;
}

wild cove
sour fulcrum
#

If statements! You already have 1 there

wild cove
sour fulcrum
#

you can check for multiple conditions by either nesting, eg.

if (thing)
{
if (otherThing)
{}
}

or you can do like

if ((firstThing) && (secondThing))
{
}

ivory bobcat
sour fulcrum
#

Are you sure that's what they are running into here

frail hawk
#

he already mentionjed that he put the code accidentaslly into the OnTriggerEnter

#

he wants it in the Update

sour fulcrum
#

you were the first and only(?) person to bring up Update unless im missing something

ivory bobcat
#

Don't recall update being mentioned

sour fulcrum
#

i think homie is just new to if statements..

wild cove
#

Naw it was in OnTriggerEnter, it is in update now

frail hawk
sour fulcrum
#

not in ontriggerenter does not mean in update

#

🤔

frail hawk
#

well it is the only place that makes sense if you lok at his code

#

he is making a runner game

wild cove
#

yeah sorry, i shouldve specified where I was going to put it

#

thats mb

frail hawk
#

so we have already provided you with all the code you need, please scroll up and read again

ivory bobcat
#

I'm assuming they've got an infinite runner where they're loading/cycling new tracks as they reach a certain point on the road. Where I'm assuming their character may be triggering the enter method repeatedly somehow

wild cove
#

alr

frail hawk
ivory bobcat
wild cove
frail hawk
#

just scroll up and read the code

ivory bobcat
ivory bobcat
wild cove
#

Sorry my internet cut out

#

Im trying to send the video rn

#

Sorry for it being short, I don't have nitro so I don't want to run the risk of it not posting, but the main problem is still the infinite levels but for some weird reason the script isn't registering the mole as a game object or something.

ivory bobcat
#

Mp4 or some other video format that's discord safe is preferred

wild cove
#

oh mb

wild cove
# frail hawk just scroll up and read the code

And Murado if your still here Idk if im dumb or what but I still don't know how to negate the script, what you told me showed me how to create something that could hold code that would negate the script, but idk any ways to actually negate the script with code

ancient nimbus
#

public class PlayerController : MonoBehaviour

#

this is the public class

#

and i put it here

public class PlayerController : MonoBehaviour

private Rigidbody rb;
ivory bobcat
#

How to post code

#

!code

radiant voidBOT
ancient nimbus
#

   void OnMove (InputValue movementValue)
   {
   Vector2 movementVector = movementValue.Get<Vector2>();
    movementX = movementVector.x; 
    movementY = movementVector.y; 
   }



public class PlayerController : MonoBehaviour

    private Rigidbody rb; 
    private float movementX;
    private float movementY;


    void Start()
    {
        rb = GetComponent <Rigidbody>(); 
    }


   private void FixedUpdate() 
   {
    Vector3 movement = new Vector3 (movementX, 0.0f, movementY);
    rb.AddForce(movement);
    rb.AddForce(movementVector); 
   }```
ivory bobcat
#

You're missing curly braces for your class

#

Hopefully that isn't exactly how the script looks

ancient nimbus
#

{ those?

#

oh nice it fixed it thanks

ivory bobcat
#

!learn

radiant voidBOT
ancient nimbus
#

thats what i'm using

frail hawk
ivory bobcat
#

You should probably go through the basic unity learn scripting tutorial

ancient nimbus
#

i am

#

is rolling ball the basic thing or no

wild cove
ivory bobcat
#

They've got quite a few basics I don't recall off the top of my mind

ancient nimbus
#

oh ok

wild cove
frail hawk
#

you are already doing it correctly. please send the code as text so we might see how it looks now

wild cove
#

'''cs

using UnityEngine;

public class LevelSpawner : MonoBehaviour
{
public GameObject CurrentLevel;
public GameObject[] LevelPrefabs;
public GameObject Mole;
private bool hasRun;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{

}

// Update is called once per frame
void Update()
{
    if (Mole.transform.position.x + 5 > CurrentLevel.transform.position.x && !hasRun) ;
    {
        int LevelIndex = Random.Range(0, LevelPrefabs.Length);
        Vector3 SpawnPos = new Vector3(CurrentLevel.transform.position.x + 25, CurrentLevel.transform.position.y, CurrentLevel.transform.position.z);
        Instantiate(LevelPrefabs[LevelIndex], SpawnPos, LevelPrefabs[LevelIndex].transform.rotation);
        hasRun = true;
    };

}

}
'''

frail hawk
#

this looks ok now for now, at least it should only run once

#

could it be that you have this script on your prefabs? because everytime you spawn a prefab then it runs this

wild cove
#

yeah I have this script on my prefabs

frail hawk
#

there you have it

wild cove
#

but also something else is entirely wrong

#

because for some reason the starting level wont pick up a game object I set as a mole as a mole

frail hawk
#

it shouldn´t be on your prefabs it doesnt make sense

wild cove
#

(as a game object)

#

oh

#

alr

frail hawk
#

you need that LevelManager one time only in your scene

wild cove
modern meteor
#

how do I move my character towards the direction im facing

frail hawk
ivory bobcat
modern meteor
#

3d

modern meteor
modern meteor
ivory bobcat
#

Rigid body add force direction multiplied by some scalar value

wild cove
#

and thanks everyone else for their help

#

I progressed and actually learned a lot from this

frail hawk
kindred temple
#

When I'm using Instantiate do the components sometimes not exist until a moment after the Instantiate method is used?

I'm getting a weird NPE which sometimes happens and sometimes doesn't happen relating to a component on an instantiated object (the component is already present on the prefab), even though the object is definitely instantiated before the component is retrieved and checked

frail hawk
#

nre?

#

or explain what you mean with npe

kindred temple
#

Oh yeah NRE sorry

frail hawk
#

do you have some code to share, what you are describing should not be possible actually

kindred temple
#

Ah never mind, turns out I forgot a check to ensure the code should be executed (and when that check is false a different object is instantiated, not the one with the component)

willow iron
#

so i want to calculate the shortest distance between one point to another. The problem is that these points are located in a maze with several paths. Every single path in the maze pre calculates how long it is. Im thinking that i should calculate every single possible path between one point to another, and then grab the path with the shortest distance. In order to calculate every possible path, I am thinking that i choose a direction, go down it, and then go down every path at the end of that path, avoiding duplicates. If i keep doing this, eventually i will reach the goal (its a pacman style maze, no dead ends). What would be the best way to do this? This feels a little above my scope.

willow iron
keen dew
#

This is just basic pathfinding. There are literally thousands of resources for this. Google for "Unity 2d pathfinding"

willow iron
frosty hound
#

There is a GitHub for a 2D navmesh, it works the same as the the built in one aside from the setup to mark things as obstacles in 2D.

red rover
#

I was just recommended by the formatter to simplify values[values.Length - 1] to values[^1], introducing me to the "index operator," where the number is the distance from the length of the array so, index 8 in a length 10 array is ^2 for example.
Seems simple enough, but are there other places where this operator is used like this?

rich adder
#

just means the index counted from end

red rover
rich adder
#

there is also .. , this page has more

red rover
#

Oooh

rich adder
#

yaa there is a bit you can do, but I think most of this is c# > 8
so if you're working with older unity or making code/assets compatible with older unity versions it wouldn't work

red rover
#

I see, thankfully I'm on 6.3 so I'm good on that front 😎

fast zodiac
#

does anybody knows how can I get rid of these suggestions. I know these are usefull but currently I'm learning Unity and I don't need them. How can I turn them OFF?

#

and I'm using VS code

real thunder
#

those are not suggestions

#

those are useful info, you don't want to hide them

red rover
#

Bro i've been coding for like 5 years without them you can totally hide them if you want to

rich adder
#

You can hide them but why would you ? its useful info..

red rover
#

It's a preference thing.

real thunder
red rover
#

I've always had it disabled and haven't had an issue

fast zodiac
#

yes I know these are useful but currently I don't need then, I'm currently learning Unity C# and these are just bothering me. I'll enable them when once I'm ready

real thunder
#

honestly I don't remember a sinlge time where the amount of references helped me, unless it's 0 which means I have forgot something

red rover
#

Personally I just see it as a lot of visual noise, and makes it more cumbersome to go up and down the code quickly.

rich adder
#

probably more useful if you have lots of public methods / cross-script referencing

#

or a monolith

fast zodiac
red rover
#

You can always just right click to see references if it's needed

real thunder
red rover
#

Do you mean the codelens setting isn't working for you?

real thunder
#

I mean... right, I mean I failed to find one for this

#

those I found and where is the other

red rover
#

I see

naive pawn
#

unity's codelens can be configured from this, which you can find by searching codelens and selecting unity in the extensions dropdown

#

you could also disable codelens altogether if you'd like, it's Editor: Code Lens

real thunder
#

now my code looks so lonely 😢

sly shard
past yarrow
#

Hey, why does this code not set the TileTypefield in my Tile script to the value corresponding to the pixelColor key picked from the dictionary please ? all the tiles are set to EN_TileType.None 🤔

swift crag
#

Did you mean to check if the new type is not NONE?

#

Your code currently checks if the current type is NONE and does nothing in that case

past yarrow
swift crag
#

but if all of your tiles start out with a type of NONE, then the set accessor of TileType will do nothing

keen dew
#

How are you planning to set the initial type of the tile?

swift crag
#

because you told it to do that

naive pawn
swift crag
#

eh, that's not a major problem

past yarrow
past yarrow
naive pawn
#

just feels like quite a yikes that would easily lead to desyncs and bugs, due to your changes not being easily immediately applied
just drawing with tiles in unity would be more configurable and easier to manage, no?

keen dew
ivory bobcat
past yarrow
#

so I should remove that if statement ?

ivory bobcat
#

Depends on what you're trying to do. Surely you've placed it there in the first place for some purpose.

swift crag
#

It appears to have two meanings right now:

  • A tile that hasn't been set yet
  • A tile that cannot ever be set, because it's an empty space in the grid
naive pawn
#

please do not crosspost. that is definitely not a code question

tight lantern
#

ok

swift crag
slender nymph
swift crag
#

i see

swift crag
#

that workflow sounds significantly nicer

#

notably, you can create your own tile classes, which lets you store whatever data you want in them

#

this also completely removes the problem of having "uninitialized tiles"

#

and other weird in-between states

past yarrow
naive pawn
#

that just.. defeats the purpose

slender nymph
#

I thought you literally had data embedded in the tilemap
that is exactly what i meant. like i told you, you can inherit from TileBase to create your own tiles that have whatever data you want on them and use those tiles to literally draw your map with on a tilemap

naive pawn
#

you can cut the image, with its lack of metadata and in-editor modification, completely out of the equation

swift crag
#

you'd also be able to use the Tilemap system to position, query, and display the tiles

past yarrow
swift crag
#

Yes, and you code says to not change the tile type if the current type is NONE

#

So nothing happens

naive pawn
swift crag
past yarrow
past yarrow
swift crag
#

that was not Chris's question

#

the question was what the default value of tileType was

#

(and since the default value was clearly NONE, your code didn't work)

swift crag
#

but, again, I must reiterate:

  • you have two incompatible meanings for NONE here, which is already a major problem:
    • a tile that doesn't exist (somehow?)
    • a tile that you haven't initialized yet
  • this entire scheme doesn't make sense; just use tilemaps
naive pawn
#

you're setting to the instantiated Tiles, i asked about the tilePrefab

past yarrow
naive pawn
#

with this setter?

#

which doesn't do anything if it's currently NONE

#

... man, please just share code properly in the future

past yarrow
naive pawn
#

!screenshots

radiant voidBOT
naive pawn
past yarrow
#

the code is this now :

//Tile.cs
using System.Collections.Generic;
using _Game.Scripts.Enums;
using Sirenix.OdinInspector;
using UnityEngine;

public class Tile : SerializedMonoBehaviour
{
    
    [SerializeField]
    private Dictionary<EN_Direction, Tile> neighbours = new();

    [SerializeField]
    private EN_TileType tileType;
    public EN_TileType TileType {
        get => tileType;
        set => tileType = value;
    }
}
naive pawn
#

-# why even have the manual accessors lol

past yarrow
# swift crag but, again, I must reiterate: - you have two incompatible meanings for `NONE` h...

the not initiliazed part is temporary, in the sense that it's the case only when I spawn the prefab then the next instruction I set it. Why I still have None, is because I need it in the 2D grid that would hold the data itself about the board as I need it to attribute neighbours in my Tile.cs class, so seeing that the tile next to me is NONE would tell me that it's a transparent pixel, so I can't use it.

past yarrow
naive pawn
#

sure

#

but really, stop relying on images and pixels

#

it's such a fragile system

#

you're duplicating data in the code you showed

past yarrow
#

alright I will try to do the tilemap thing but I have no clue how

naive pawn
#

"single source of truth" is a good rule of thumb for a reason

naive pawn
verbal swift
#

How stupid am I for trying to make a movement shooter while being absolutely terrible at physics

solar hill
#

do you have a question

naive pawn
#

those are kinda unrelated

solar hill
#

i wouldnt say they are completely unrelated

naive pawn
#

physics is far from the most important aspect

solar hill
#

its not important but a lot of good controllers do custom physics for certain aspects

#

so theres an element to it

verbal swift
#

There is alot of physics in momentum forces n stuff

solar hill
#

i just dont see how this is important to this channel or what your question is Zone.

verbal swift
#

So true kuzmo I am so humbly sorry for dare speaking in your code beginner channel about my challenges with trying to make a physics based system while being bad at physics

naive pawn
# solar hill so theres an element to it

if you focus on those, sure. but on an overview, on a broad topic? imo, not that necessary to have going in. very useful, but not absolutely crucial. you can learn it along the way anyways, like everything else

solar hill
#

this is a help channel, if you want help you have to actually ask a question

naive pawn
#

if you need help with something, you're free to ask, but we aren't psychic, we won't know until you ask lol

solar hill
turbid nebula
#

Hi guys i am new

bronze thunder
#

not sure where to ask for this, but I can't find reference for the List type. The most helpful thing I could find was this forum topic which is itself now defunct. Is the scripting API reference for List accessible somewhere?

naive pawn
keen dew
#

Google for "C# list". It's not a Unity concept.

bronze thunder
#

ah ok, thanks

naive pawn
#

you can hover over types in you ide to see what namespace they're from. anything under System is a c# thing, anything under Unity/UnityEngine/UnityEditor is a unity thing

keen dew
#

Also there's a direct link to the C# List documentation in the thread in the screenshot

bronze thunder
#

the thread doesn't even open for me, though maybe thats on my end

shell sorrel
#

just search C# list

#

first result should be the one

bronze thunder
#

oh I see the discussions is the new forums, I saw it didnt load and vaguely remembered an article about the forums shutting down so I thought it was defunct

shell sorrel
#

like mentioned above only some things are provided by unity the rest of it is part of the C#/.net standard library

wintry dew
#

I have no idea why the gui of the serialized lists in every object are behaving like this, but sometimes randomly i get about 50 unity errors that a bunch of code outside of my scripts, like the actual engine code, is causing errors

#

not even during runtime either

slender nymph
#

you need to update to a newer patch. that bug was fixed a couple months ago

wintry dew
#

do i have to install a new version of unity?

slender nymph
#

that is how updating to a new editor version works, yes. but you don't need a completely different version, just the same version with a newer patch

wintry dew
#

alright

remote spade
#

Hi yall, someone knows how can i get a bool from another script file, like i have a bool in the player script file and i have to get it in the wall script file too

remote spade
tired python
wild cove
#

!code

radiant voidBOT