#💻┃code-beginner

1 messages · Page 529 of 1

ashen isle
#

one sec

#

ok so THATS what serialize field means

#

honestly i was confused on why its was a string

#

ok this is my new code so the parenthesis is the field that i can change in the inspector and the other value is the default?

frail hawk
#

until you change it in the inspector

ashen isle
#

WAIT i think i just had an aha moment one sec

neon ivy
#

in general, making a behaviour tree system

ashen isle
slender nymph
ashen isle
#

i did all that before i started but its giving me this error

#

it says the unity extension is installed and i did all the other steps on there

slender nymph
#

you need to install the .net sdk. helpfully there is a convenient button to click to get it

ashen isle
#

this one?

slender nymph
#

well that will be a tool that will install it

#

is that what appeared when you clicked the Get the SDK button? 🤔

ashen isle
#

yeah i see it now, but the popup went away, i'm really sorry i rlly should have just looked.

slender nymph
#

scroll up in the output console and there will be a link to download it there too

ashen isle
#

its not there

rich adder
slender nymph
#

have you restarted your pc? the extension seems to think it was installed but just isn't in the path

rich adder
#

words mean things

ashen isle
#

👍

#

i was scanning for a link my b

orchid flare
#

anyone know where I can find an expert in ML-Agents (or Unity in general?) I guess they don't allow job posting on the server but if someone could get me in the right direction I would appreciate it

steep rose
oak grail
#

hello i have question , create GameManager Script and have one problem. script dont create gearwheel and i cant move this in inspector slot.

orchid flare
steep rose
#

!collab would be your best bet for collaboration

eternal falconBOT
#

: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

orchid flare
#

I know

rich adder
orchid flare
#

but perhaps does someone know someone who I could contact outside the server

steep rose
#

for AI in particular? you could contact the local google search to find someone

#

other than that I do not think anyone knows anyone in particular, so the link I sent above would be your best bet

orchid flare
#

ok thanks

#

i mean some people here would probably be who im looking for but they don't allow job posting here right

steep rose
oak grail
rich adder
oak grail
#

ooook, but why i cant move script to Inspector ?

nocturne kayak
#

Alright, so, back on my events stuff and

#

i'm trying to use this script

rich adder
nocturne kayak
#

trigger this script

#

but am getting a nullreference exception

#

what gives?

rich adder
#

second link is blank

nocturne kayak
#

my bad

rich adder
#

needplacement manager

nocturne kayak
slender nymph
#

Selector_Script.current is null

#

because you are accessing it before it has been assigned. you should really look up how to set up a singleton correctly so you don't run into these issues where you try to access it before its even been assigned

rich adder
#

make sure you initialize anything, including a singleton in Awake

#

everything else that use those use Start

slender nymph
#

these singleton objects also do nothing at all to ensure that only one of them ever exists at a time

rich adder
oak grail
#

this is two test script

marsh glade
#

Hi, how do I set the position of a transform relative to another without them being parented to one another please ? I'd basically like to put one object on top of the other, so Vector3.zero in the local space of the other object

rich adder
#

unity doesn't like that

nocturne kayak
#

Alright, i put the reference to the selector_script in awake and it seemed to work, correct me if i'm wrong but essentially what happened was that PlacementManager was trying to get the Selector_Script before that reference even existed, right?

slender nymph
cosmic dagger
oak grail
nocturne kayak
#

I thought singletons were simply scripts you only use once, or in a single gameobject

rich adder
rich adder
nocturne kayak
#

i can access github just fine

marsh glade
cosmic dagger
vestal adder
#

multipleton

slender nymph
marsh glade
rich adder
neon ivy
brave socket
#

Camera Dragging Issue in Unity

clear river
#

I am using the NavMeshAgent from the unity tutorial to get pathing from A -> B in a 3D space. Everything seems to work fine with this. However, I created a script and I have to attach the NavMeshAgent to a variable in the script. I do this with:

void Start ()
{
    this.agent = GetComponent<NavMeshAgent>();
}

If I do this and press 'Play', Unity crashes and I have to ctrl+alt+delete end Unity... Anyone knows whats up?

urban chasm
#

hey guys, sorry for interrupting, but i have a question

cosmic dagger
slender nymph
urban chasm
#

so i have this code for my animations, its a top-down rpg kind of game, and it does work, but that many if statements might lag the game in the long run and its just annoying to look at, is there a way i could simplify it?

clear river
slender nymph
#

yes, you can use the debugger and break all when it freezes. then inspecting what the main thread is doing will show you where your infinite loop is

rocky canyon
#

yes, breakpoints

clear river
#

Because it seems that I have no infinite loops. It also crashes when I add this component to the public variable during runtime.

slender nymph
#

show the entire class

rocky canyon
urban chasm
#

so something like: *** if (v > 0 ) {etc} ***

rich adder
#

for game, you should be more worried about renderers and assets lagging your project before anything else..

clear river
slender nymph
#

!code

eternal falconBOT
cosmic dagger
ashen isle
#

first function works, second one doesn't pop up in on click field

rich adder
slender nymph
#

this is not what i meant when i said you can reuse the component btw

ashen isle
#

oh well lol

frail hawk
rich adder
#

that local variable is useless

slender nymph
ashen isle
#

sorry i got confused, but it was easier and made more sense to me to change the string value within the function instead of in the inspector

rich adder
#

the whole point is to have each one of these with a diff scene name

cosmic dagger
rich adder
#

not everytime you want to add an entry/method for that scene you have modify the file

#

instead of having 1 file that serves multiple purposes

clear river
ashen isle
frail hawk
#
public void LoadSomething(string sceneName)
{ Load sceneName }
#

you need a method where you can feed in the scene name

rocky canyon
# urban chasm so something like: *** if (v > 0 ) {etc} ***
    public Animator animator;
    private float horizontal;
    private float vertical;

    void Update()
    {
        horizontal = Input.GetAxis("Horizontal");
        vertical = Input.GetAxis("Vertical");
        animator.SetFloat("Horizontal", horizontal);
        animator.SetFloat("Vertical", vertical);
    }```
soemething like this
#

two variables between -1 and 1 passed to the animator.. it'll use those to blend between the 4 different animation types

slender nymph
clear river
rich adder
#

I always put a while loop in Coroutine another good way it dont hang the Update loop

slender nymph
#

what is likely happening is that you are instantiating the object within 5 units of a tree, which means on its first Update, it enters that infinite loop. and because you aren't incrementing its resourcesGathered variable (i assume since you've not shown the StartCuttingTree method), the loop never ends

#

you're also relying on strings for the states which is . . . not great. and your if statements are all separate making it possible to cycle through multiple states all within a single frame

ashen isle
#

ok last attempt i filled in the field as "MainMenu" which is my scene name but the functionm is not showing up in the on click event space

clear river
#

Mhh, let me spawn my inhabitant somewhere far

cosmic dagger
rich adder
#

i bet you dragged the script from the project folder and not the instance

cosmic dagger
#

then we need to see how you setup the OnClick button from the inspector . . .

ashen isle
clear river
#

I gotta come clean. It was an infinite loop. Exactly like you described with the cutting tree. Thank you all so much for helping me out!

rich adder
rich adder
#

you need to drag the Instance thats on a gameobject

rich adder
cosmic dagger
# ashen isle

you have to drag the GameObject that has the script attached to it in the field, not the actual script (from the project folder) . . .

ashen isle
#

ok cool

lunar hollow
#

What is the best most Memory Efficient way to get a Camera's (which isnt rendering to a RenderTexture) Image in sprite format?

rocky canyon
#

^ ur fillin the variables of an instance of the script (gameobject w/ script attached).. not the actual script

rich adder
ashen isle
#

thank you so much it wasa driving me insane

#

OH now i get why its because the public string is attached to thye game object

rich adder
#

every time you attach a script to a gameobject a new instance is created of that script, each has their own version of the data

ashen isle
#

awesome thank you so much sorry that was so frustrating I'm working on paying more attention to things and problem solving

rich adder
#

takes time, and also experience which comes with time so all you need is time and patience to learn

rocky canyon
upper yoke
#

Hi, I need to to update a TMP_Text in a Task.Run (because i do some others async operation there) but when I do so the text isn't updated in Unity, even if it is in the inspector
I tried to use ForceMeshUpdate(true); but it didn't change anything
Would anyone have any advice on that?

slender nymph
#

Task.Run schedules the task to run on the threadpool which means it may not run on the main thread. you cannot use the majority of the unity api off of the main thread so that won't work

cosmic dagger
#

i unsure if that runs/works on the main thread. if not, then it won't update . . .

upper yoke
#

Is there any other way to call async function for Unity?

cosmic dagger
#

use coroutines . . .

rich adder
#

you can call async just fine, they are referring to another thread, something different

wintry quarry
slender nymph
cosmic dagger
#

are you not using async/await?

upper yoke
wintry quarry
upper yoke
wintry quarry
upper yoke
rich adder
#

btw in the new Awaitable class you can switch to the main thread for specific functions to run within that Task

wintry quarry
#

programming is all about indirection/layers of abstraction. Use them

wintry quarry
#

Be specific

#

what are you doing

upper yoke
#

I'm using an external library that have a method such as "ConnectAsync"
So in my settings when i click to the connect button the text keep track on when it's connected

slender nymph
upper yoke
#

I'll try that

wintry quarry
#

if it's truly async

upper yoke
upbeat wind
#

how do I clamp the camera from looking to far left and right? my character is stuck in a chair for my game so I need to lock how far they can look left and right but I'm only finding stuff about clamping the y axis on google

slender nymph
#

exactly the same way you do it for the Y axis

upbeat wind
wintry quarry
#

BTW looking left and right generally is rotation around the y axis.

upbeat wind
wintry quarry
#

Change compared with what?

#

You'd need to explain what existing thing you're talking about

upbeat wind
#

I have the y axis clamped so the player can't look to far up or down, so would I run another code like that one but change the order of the cords I'm changing?

zenith cypress
#

x is up and down

upbeat wind
#

man this changes everything I knew about coordinates( tbh my only knowledge was from minecraft)

zenith cypress
#

Think about it as rotating around an axis. Left to right rotates around the Y axis. Up and down rotates around the X axis.

rocky canyon
#

up down.. like u got a skewer thru the X
left right.. like u got a skewer thru the Y

rich adder
#

🍢

upbeat wind
#

would I need to create something for the camera to pivot from or can I just clamp the camera it's self?

rich adder
#

you clamp a float only to pass to camera x

#

I make camera child of empty so I can create recoil without affecting cam

slender nymph
#

the easiest way to achieve this is to use cinemachine which can allow you to enable/disable the rotation clamping at will super easily

pure quiver
#

when i use unity i dont see that

rich adder
#

are you using unity 6?

pure quiver
#

yes

#

im new

slender nymph
rich adder
rocky canyon
#

i just stack them all together on the left

rocky canyon
onyx ledge
#

im new att scripting/programing in Unity and i dont know if this is a problem or not but in others code i have seen this "using System.Collections; using System.Collections.Generic; using UnityEngine;" but i can only have "using UnityEngine;" in my code. is that a problem or am i overthinking?

onyx ledge
#

okay

thorn tapir
#

would a statemachine be appropriate for handling UI? To ensure that players can't bring up the inventory while they're in the pause menu and things like that. Or is there a better way to handle this that I'm unfamiliar with?

teal viper
wintry quarry
#

That's the only thing using XXX does - it lets you write the short names for types without the full namespace.

gray bough
#

Hi! I'm working on a jigsaw puzzle and I can't figure out why my remainingPieces variable doesn't count down correctly. It only ever decreases by 1 no matter what pieces are placed. Can anyone look over this and help me? This is just the function it is in but I can share more of the code if needed.

teal viper
gray bough
#

I need it to iterate everytime a piece is placed

teal viper
#

Iterate?

#

Iterate what?

gray bough
#

sorry, to keep decreasing every time another piece is placed

teal viper
#

Does it not?

proper bobcat
#

How are you verifying that its not working correctly?

#

Are you printing out remainingPieces somewhere

gray bough
#

in game mode, I can see the value of remainingPieces.

proper bobcat
#

And it goes down by 1 each time? Or only really ever does it once? meaning from 12 -> 11 and thats it

gray bough
#

it only every goes from to 11 no matter how many pieces are placed

proper bobcat
#

Is the logic running more than once? If it isn't it means that your logic isnt being entered

#

Your conditionals are false except for once

teal viper
proper bobcat
#

If you don't see the print every time you get rid of a piece, my guess is it has to do with the Name conditional

teal viper
#

Yeah, these conditions do look very suspicious.

#

Honestly I don't really get the logic behind them.

gray bough
#

yes i see the "subtracted one" more than once

#

I was following a tutorial

#

I can send more of the code if that will help

proper bobcat
slender nymph
#

i'm gonna go ahead and guess we are looking at logs from different objects. or you've omitted some other important code

gray bough
#

This is not a very long script. I can send if that will help

slender nymph
#

sure. but just to confirm, these logs are all coming from the same gameobject, right?

gray bough
#

Different. This script is on all the picture pieces because that's what the tutorial did😢

slender nymph
#

well that would be why then. each instance of this component has its own remainingPieces variable that is entirely separate from the other instances

gray bough
#

I'm not sure how I should split up the script so all the pieces can move and remainingPieces will be calculated

slender nymph
#

separate the logic out. have one central object that keeps track of all of the pieces, and have each piece tell that managing object when it's been used/placed/filled/whatever

gray bough
#

I'm new to referencing c# scripts in other scripts so can you please help me how to divide this out : (

slender nymph
proper bobcat
#

Either make it static meaning it would belong to the class and not the instances (not advisable), or make some manager object that keeps track of this and not the pieces keeping track of it.

slender nymph
#

making it static would mean they can't assign to it in the inspector

gray bough
#

so keeping all the code that allows the object to move and check it's placement in one script, how would each piece report to a manager script that it is correct and subtract from total remaining pieces

slender nymph
#

by getting a reference to that manager object and calling a method or decrementing a variable or by raising an event that the manager object subscribes to

gray bough
#

ohhh okay. so instead of referencing the movePiece script in the manager script I should reference the manager script in the movePiece script?

slender nymph
proper bobcat
#

The cleaner way would be to have the manager script get a reference to each piece. Each piece could fire off an event when its 'collected'? or killed or whatever happens when your piece is subtracted. The manager subscribes to (listens for) this event and subtracts from the total number of pieces in response to the event in its own function.

gray bough
#

😢

proper bobcat
#

Whats there to be sad about lol?

gray bough
#

I'm just so lost on how to do this

proper bobcat
#

Do you have a manager script yet?

gray bough
#

I just made it so it's empty rn

proper bobcat
#

I'll give you a high level overview.

  1. Have a manager script get a reference to all the pieces.
#
  1. Stick them in a list for now.
#
  1. Use loops to achieve this. While looping, subscribe to an event that the piece script will fire off at some point.
molten pulsar
#

hi i have a question i use rig builder.build in update to update two bone ik constraint in every fps and when arms gets to the target goes like crazy theres any solution to that?

proper bobcat
#

In the piece script you could, at the top of the script, declare an action like so,
public event Action PieceSelected;

gray bough
#

I have never used an event like that😶

proper bobcat
#

Its ok, its a powerful tool and pretty simple to use

#

I can walk you through it pretty quickly

#

let me know if you want to, or if you create it or whatever

gray bough
#

I'm cutting and pasting the code that handles the win state and remainingPieces and this is the code I have for checking if a piece is in it's correct place. If I can use this, how can I then send to the manager script to subtract ?

proper bobcat
gray bough
proper bobcat
#

Ok so in here you would fire off the event if you created it already

#

PieceSelected?.Invoke();

gray bough
#

how would i do an event in here☹️

proper bobcat
#

Where you want to subtract from the total amount

#

just put that piece of code I just pasted. Did you create the action earlier when i typed it from above?

gray bough
#

yes I did

proper bobcat
#

Ok so just do the invoke somewhere inside that if statement

proper bobcat
#

cool.

#

Ok thats all from inside the piece script. Just to clarify. You created an Action event. And wrote code where and when it should fire off.

#

Now into the manager script

#

do you have any references yet at all to the pieces from inside the manager script?

gray bough
#

So, no I don't think I have references to them. The movePiece script is just attached to every puzzle piece

proper bobcat
gray bough
#

This is everything in my move piece script

gray bough
proper bobcat
#

Do the pieces have some common GameObject parent?

gray bough
#

no but I can make one

proper bobcat
#

Theres many ways to get references to GameObjects and Components. We will do simple for now.

#

How bout in the Piece manager script, you create a serializedField List to store the pieces in and then show me its made

gray bough
#

or does it need to be a GameObject?

naive pawn
#

unity can serialize ints just fine

proper bobcat
#

I mean preferably I would make it the class that is your Pieces

#

like if your pieces are Piece then the list could be List<Piece> pieces;

#

The word piece just looks wrong now. I've read it too much.

gray bough
#

in this manager script i only have an int for remainingPieces

proper bobcat
#

Thats fine, did you create the list?

#

the list should not be int

#

Its not going to be a list of ints

#

Its going to be a list of the pieces

gray bough
proper bobcat
#

What did you name your script for your pieces?

gray bough
#

ohh okay thank you

proper bobcat
#

yupp

gray bough
#

got it fixed

proper bobcat
#

Cool. Ok. Now open the editor. Go click on the GameObject with your manager script on it.

#

You should see the serialized empty list.

#

You can select and drag all the piece GameObjects into this list I believe

#

You may need to lock the inspector so it doesn't switch while you are trying to drag and drop

#

Which you can find there

gray bough
#

got the list filled in

proper bobcat
#

Coolio. Now lets create a private void OnEnable() method in the manager script as well

teal viper
proper bobcat
gray bough
proper bobcat
#

Ok. Lets create a simple foreach loop. It simply loops over each thing in the list.

teal viper
proper bobcat
#

foreach (var piece in Pieces){}

gray bough
#

in OnEnable() correct?

proper bobcat
#

Yupp

gray bough
#

👍

proper bobcat
#

Ok. inside the loop we are just going to subscribe (listen for) the events that each piece has.

#

piece.EventActionName += SubtractFromTotalPieces

#

replace EventActionName with the name that you gave the event in the Piece scripts

#

SubtractFromTotalPieces is just a name I came up with. This is going to be the name of the method you need to make that will contain the code that will subtract from the remainingPieces

#

Thats.....it, really. There is some good practices to do as well but lets see if this works first.

gray bough
#

Thank you so much

proper bobcat
#

Thank me when its over lol

gray bough
#

I created the subtractFromTotalPieces func

proper bobcat
#

Awesome, it needs to be exact name of the func minus the ( ) in the foreach loop part

#

test it out if you have the code that subtract from remaining pieces already written

gray bough
#

I just cut this from the movePiece script

proper bobcat
#

cool, give it a rip

gray bough
#

it works!!!

#

thank you so much😭 🙏

proper bobcat
#

This is essentially what we did

#

Use these tools every day and you will fly and better understand them as you go. Continue to make lists, loops, events!

wheat ingot
#

This error randomly showed up out of nowhere and I can't figure out how to fix it

#

when I double click it, the inspector seems to bring me to a file called "Graph"

#

Driving me wild

teal viper
#

Clear the console and see if the error appears again.

wheat ingot
#

Lowkey was freaking me out

polar acorn
light briar
#

Anyone have ideas on why I'm getting this error?

FishGenerator:
https://pastebin.com/HbvbHN37

FishingPool:
https://pastebin.com/ehqbDFGM

Json File:
https://pastebin.com/eLP5hXzU

#

For some extra context, I'm attempting to generate a fish with random things chosen from the JSON file so it's not hard coded variables.
But I am having issues trying to get it to override the FishingPool using the Unity JSON utility

light briar
#

Yeah I'm kinda genuinely at a loss because from everything I can find, I did it right?

north kiln
light briar
timber tide
toxic frigate
#

hello everyone, does anyone know why this says type mismatch once i assign it?

void GenerateAndAssignNoiseTextures()
    {
        // Generate shape noise (Texture2D)
        Texture2D shapeNoise = GeneratePerlinNoise(resolution, shapeNoiseScale);
        effectScript.cloudSettings.CloudNoiseTexure = shapeNoise;

        // Generate detail noise (Texture3D)
        Texture3D detailNoise = ConvertToTexture3D(GeneratePerlinNoise(resolution, detailNoiseScale));
        effectScript.detailCloudSettings.DetailCloudNoiseTexure = detailNoise;

        // Generate weather map (Texture2D)
        Texture2D weatherMap = GeneratePerlinNoise(resolution, shapeNoiseScale * 0.5f);
        effectScript.cloudSettings.WeatherMap = weatherMap;
    }
#

all of the variable types are correct

wintry quarry
toxic frigate
wintry quarry
#

You'd have to show us the other code here

toxic frigate
#

like this:
effectScript.cloudSettings.CloudNoiseTexure = shapeNoise;

wintry quarry
#

Whatever effectScript is

#

And cloud settings

toxic frigate
#

its a scriptablerendererfeature, so unless theres something really simple and dumb or there are restrictions on scriptablerendererfeatures im not sure why it doesnt work

wintry quarry
toxic frigate
#

runtime

toxic frigate
toxic frigate
#

so i added this debug log at the end:

// Generate textures
        Texture2D shapeNoise = GeneratePerlinNoise(resolution, shapeNoiseScale);
        effectScript.cloudSettings.CloudNoiseTexture = shapeNoise;

        Texture3D detailNoise = ConvertToTexture3D(GeneratePerlinNoise(resolution, detailNoiseScale));
        effectScript.detailCloudSettings.DetailCloudNoiseTexure = detailNoise;

        Texture2D weatherMap = GeneratePerlinNoise(resolution, shapeNoiseScale * 0.5f);
        effectScript.cloudSettings.WeatherMap = weatherMap;

        Debug.Log("Textures assigned to Effect script in editor.");

and its printing it without any errors in the console but it still says type mismatch

teal viper
#

And it's details

toxic frigate
#

if you mean the debug log:

teal viper
toxic frigate
#

oh

#

this is what i meant

teal viper
#

And cloud noise texture actual type?

teal viper
toxic frigate
#

this is how i create it:

#

let me find a code pasting thing actualy

grave sinew
#

im getting null reference exception but i can't figure out whats wrong

#

im following the 2d beginners whatever

#

aparently the problem is line 18

toxic frigate
#

you dont have those variables

grave sinew
#

dumb it down for me

toxic frigate
#

you need an isPressed boolean, and im assuming keyboard, current, and the arrow keys are part of unity's new input system

#

unless the tutorial says otherwise

grave sinew
#

this code was copied and pasted from unity's own tutorial

grave sinew
#

i think unity is stroking out

charred spoke
#

Is your project configured to use the new input system ?

grave sinew
#

should be?

charred spoke
#

It’s a yes or no question.

grave sinew
#

how do i check

#

theres a reason i put this in beginner man

frozen pebble
#

Edit > Project Settings > Player, make sure Active Input Handling is "New Input System" or "both"

grave sinew
#

it was on old

#

i fixed it

#

thank you!

queen adder
#

How do i enable nullable in csproj without unity overwriting it everytime i renegerate project file ? I'm tired of adding # nullable enable on every file

burnt vapor
queen adder
#

yeah i'm tired of writing that every single time

burnt vapor
#

Alternatively you might be able to add a Directory.Build.props file next to your sln or csproj file. You have to add this to it:

<Project>
    <PropertyGroup>
        <Nullable>enabled</Nullable>
    </PropertyGroup>
</Project>
#

Not sure if Unity supports this but modern .NET does

#

Try it and seeeeeeeeeeeeeeeeee

queen adder
#

I saw that answer on stackoverflow but one comment said it is ignored in unity 2022, havent tried myself though

#

Let me try i guess, txn

burnt vapor
#

Yeah otherwise you're out of luck (probably)

#

Unity works on updating its codebase to modern .NET in which case it's probably enabled by default

queen adder
#

Um it is disabled by default, hence why im tired writing nullable enable

burnt vapor
#

I know that, I mean that future .NET versions have it enabled by default

#

Not the current one

queen adder
#

ooh i didnt know, txn

bold quail
#

hey guys

#

im new to this game thing

#

can anyone help me, im making pvz through a tutorial on youtube but i cant seem to get it right

#

theres a bug in my game and im completely lost

onyx tusk
#

i have an rectTransform object with height set to canvas height but it's higher. y?

eternal falconBOT
bold quail
#

im trying to drag the sunflower to the game field but when i do that it came looking like this at it changes it scale scale whenever i try to hold and drag my mouse, any idea what causes this. im already using rigibody2d and made it kinetic

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class ObjectCard : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler
{
    public GameObject object_Drag;
    public GameObject object_Game;
    public Canvas canvas;
    private GameObject objectDragInstance;
    public void OnDrag(PointerEventData eventData)
    {
        objectDragInstance.transform.localScale = Input.mousePosition;
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        objectDragInstance = Instantiate(object_Drag, canvas.transform);
        objectDragInstance.transform.localScale = Input.mousePosition;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        throw new System.NotImplementedException();
    }
}
#

this is the code

silk night
bold quail
#

thanks 😄

frozen pebble
#

Try using localPosition instead

bold quail
#

thanks 😄

#

it worked

kind skiff
#

Hey guys, I have just started out with unity

#

And I'm trying to make an FPS game

#

However, when I go around with the youtube tutorials

#

It ask me to use CharacterController.IsGrounded to check whether it is grounded or not

#

But it seems unreliable as sometimes the isgrounded will be false even though the character is already touching the ground

#

Why is that??

bold quail
#

Hey guys, I need help again, I dont know why when i placed my sunflower on the container it becomes so small, theres a comparison between when im dragging on the container. heres the code for the PlaceObject function implemented in GameManager

using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject draggingObject;
    public GameObject currentContainer;

    public static GameManager instance;

    public void Awake()
    {
        instance = this;
    }
    public void PlaceObject()
    {
        if (draggingObject != null && currentContainer != null)
        {
            Instantiate(draggingObject.GetComponent<ObjectDragging>().card.object_Game, currentContainer.transform);
            currentContainer.GetComponent<ObjectContainer>().isFull = true;
        }
    }   
}

Any ideas as why its like that?

#

this is the code for objectContainer

#
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;

public class ObjectContainer : MonoBehaviour
{
    public bool isFull;
    public GameManager gameManager;
    public Image backgroundImage;
    public void Start()
    {
        gameManager = GameManager.instance;
    }
    public void OnTriggerEnter2D(Collider2D collision)
    { 
        if (gameManager.draggingObject != null && isFull == false)
        {
            gameManager.currentContainer = this.gameObject;
            backgroundImage.enabled = true;
        }
    }
    public void OnTriggerExit2D(Collider2D collision)
    {
        gameManager.currentContainer = null;
        backgroundImage.enabled = false;   
    }
}
#

am I missing something?

#

should i re adjust the height and weight when its dropped?

wintry quarry
#

Presumably the container has been scaled

#

Child objects inherit the scale of their parents

#

It would be best if the container object is not scaled so you don't have to worry about it

bold quail
buoyant finch
bold quail
#

and i should make the scale of the container 0 0 0 ?

wintry quarry
bold quail
#

i am so lost, i changed the width and the height but its still so big

#

after i changed the scale to 1 1 1 😅

#

any idea on how to make it smaller?

normal tapir
#

using UnityEngine;

public class PlayerController : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
private Rigidbody2D test;
[SerializeField] private float jumpForce = 10f;
void Start()
{
test = GetComponent<Rigidbody2D>();

}

// Update is called once per frame
void Update()
{
    if () {
    Input.GetKeyDown(KeyCode.Space);
    }
}

}

Ok im currently learning C# dont laugh abt my code 💀
Invalid expression term ')'
what do they mean with this error

bold quail
#

im no expert but i think its ur if statement

#

i dont think u could left it blank like that

normal tapir
#

yea it was if statement

#

i fixed it

#

void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
test.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
}

#

hehe bit stupid of me

eternal falconBOT
burnt vapor
#

We already told you this yesterday

#

There is no point in helping you with such basic issues, especially when your editor would do that if you actually configure it

normal tapir
#

xD

#

i never said i had issues with the ide

burnt vapor
#

It doesn't matter what the question is

normal tapir
#

why

#

xd

#

so i can't ask questions??? LOL

rocky canyon
#

not until u config ur IDE..

normal tapir
#

i have configured my IDE

#

xd

rocky canyon
#

i mean you can but they'll go unanswered

normal tapir
#

so that is not the question or problem

burnt vapor
normal tapir
#

i already had my IDE configured XD

burnt vapor
#

Show a screenshot of your editor

normal tapir
normal tapir
burnt vapor
#

Then you need to learn to read your code better because your editor would be very clear where it finds issues

normal tapir
normal tapir
#

well doesnt really matter all that much

#

hope yall have a great day

#

im going to develop further 😄

#

well learn xd

#

God bless yall

burnt vapor
# normal tapir

Great, next time you should learn to read the code because your editor has a nice red squiggly line underneath places where there is an issue. Just like in this screenshot

rocky canyon
#

red squigglies for the win

burnt vapor
#

Yeah idk how they could not notice this

#

Bold of me to assume it's a misconfigured editor 🤷‍♂️

rocky canyon
#

no clue, just giving a demonstration for what it i should look like..

normal tapir
#

i asked what the problem with the error was XD i gave the erorr

normal tapir
#

idk why you guys keep talking further if the problem is finished 😆

normal tapir
normal tapir
#

you guys tried to help me that is kind 😄

slender nymph
#

this is a code channel

lime hound
#

oops

#

missclicked on the channel list. Sorry!

dire cloud
#

do anyone know how to code so when i look with my player only the upper body rotate and not my legs. i have legs and upper body as different gameobjects.

silk night
#

then just rotate the transform of upper body

dire cloud
#

oh ok thx

final sluice
#

How do I make a ball rotate on the surface ? Do I use transform.rotate or is there a better way ?

rocky canyon
#

transform.rotate would make it just spin in place..
would need a rigidbody and something like rb.AddTorque i would guess

stone lily
#

hello guys, does anyone know how do i make an endless 2d background?

stone lily
#

i mean, like a endless jetpack joyride BG

#

not using a paralaxx BG, cuz im trying the 2D basic one

final sluice
#

tks

rocky canyon
#

check the outro and see if thats what you mean?

stone lily
#

is it appliable to 19:6 res?

rocky canyon
#

with a bit of critical thinking yes

stone lily
#

alright, thankyou

#

i might be try it first

#

ill report later

rocky canyon
real thunder
#

okay so if I make
bool flag = variable > 0
it's set in stone that it's true if variable is more than one the moment it called?
it's not a "pointer" to that equation and I would need to make a method for that, right?
just double checking

wintry quarry
#

same as 1 + 1

#

the > operator is just like any other

#

bool variables cannot hold "pointers"

real thunder
#

I just had a wild assumption for some reason

wintry quarry
#

You could make a property like bool flag => variable > 0;

real thunder
#

maybe

wintry quarry
#

that would be a property (not a variable)

#

which is a function

real thunder
#

makes sense

wintry quarry
#

That's basically equivalent to:

bool GetFlag() {
  return variable > 0;
}```
real thunder
#

yeah, I recall how properties works

#

however I am pretty blind to those => thingies

#

people tend to use that so called sugar oftenly and I am just getting confused there usually

silk night
#

its "basically" just a shorthand for a function

#

not litterally, theres a lot of different stuff happening under the hood, but as an end-user it works almost the same on the higher level

brave compass
wintry quarry
#

yeah normally the property is:

bool Flag {
  get {
    return variable > 0;
  }
}```
Shorthand way is:
```cs
bool Flag => variable > 0;```
silk night
#

Also if you want the "pointer" way you described, look at UniRx / R3 and their ReactiveProperty

real thunder
#

is that any different from making a usual property?

brave compass
#

You can't store a property in a variable, unless you store it as a method reference. Reactive libraries store these properties in objects that can easily be passed around.

real thunder
#

oh, right

wintry quarry
#

How is that different from a delegate?

real thunder
#

less annoying to use I would assume?

wintry quarry
#

delegates are super easy!

real thunder
#

yeah, but that might be faster to use

#

anyway I don't need neither at the moment, I am just curious

brave compass
steep rose
#

are arrow functions => lambda expressions or are they something else completely?

#

I have never used them before and they are probably great for short functions

brave compass
real thunder
#

I hate seeing it in other people's code ><

#

Nice to know at least that it's not just lambda expressions

#

I mean wise versa...

#

I was always assuming it's a lambda expressions and it's too hard for me to comprehend

real thunder
steep rose
# brave compass It depends on the context. The same symbol is used for two different things, lam...

ah, so expression bodies are basically just short functions, Although I would have to look into the documentation more to learn how to use them properly
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members

celest moss
#

How can I find out that the "model" objects in my picture are actually children of an fbx file and not the fbx file itself? Because if I get the AssetPath for these gameobject it returns the .fbx path, but that's different

#

I am validating these objects so I need to reliably skip the prefab and fbx and only look at the objects with the empty icon

real thunder
#

unless you really need a code for that

celest moss
#

I am sending the base prefab into my validator and checking all the gameobjects, two of those gameobjects will always be the prefab itself and the fbx, and I want to ignore those.

#

What do you mean change the base fbx?

real thunder
#

I wasn't helpful

#

I just told that if you open the fbx you can manually compare what was there at the start and what was added later

#

because you can't override fbx prefab

celest moss
#
GameObject go = PrefabUtility.GetCorrespondingObjectFromOriginalSource(transform.gameObject);
string assetPath = AssetDatabase.GetAssetPath(go);
if (assetPath.EndsWith(".prefab") || transform.name+".fbx" == assetPath.Split("/").Last()) 
{
    continue;
}

This is the best I can come up with, the prefab can be skipped as it has .prefab and the fbx can probably be skipped because the name+".fbx" will match the last part of the asset path on that object. But if some crazy person on my team names a model the same as the fbx file it will be skipped due to a false positive

real thunder
#

I would avoid that issue because every time I use an fbx in a prefab I am unpacking it

#

wonder if that makes something worse

celest moss
#

That's a nice idea but it would break so many other unrelated things

real thunder
#

like what?

celest moss
#

We have lots of custom pipeline tools that would make that a very dangerous change and break stuff :p

real thunder
#

I was asking if it may hurt me 😛

#

Like am I doing a bad practice

celest moss
#

You are losing the link to the fbx so it could be hard to reload or locate?

real thunder
#

makes sense

#

I should probably stop doing that

celest moss
#

I recreated a shortcut from Unreal Editor that lets me press ctrl+b to select the selected object in my project. So it's nice to have the fbx in the prefab so I can find it instantly

#

Unreal has so many nice quality of life tools that Unity just completely lacks that you have to make by yourself

real thunder
#

you should be doing with that question in code-advanced I feel

celest moss
#

Like snapping selected objects to the nearest meter on the grid

celest moss
#

It's not my company ;)

real thunder
#

I keep forgetting it's not all about small indie devs...

rocky canyon
#

tbh.. i prefer unity b/c of how easy it is to create my own tooling.. vs Unreal which i'd have to rely on things just being there to begin with

#

snapping object to the grid is relatively easy, anyway.. move it to a single digit transform, then toggle grid snapping w/ 1 unit

real thunder
#

at the same time Unity is kinda closed while you are free to modify Unreal source

#

...not like most people would do that tho

rocky canyon
#

you'll have to take it to google... modding topics aren't allowed

real thunder
#

is there a Unity modding Discord I wonder

rocky canyon
#

probably ¯_(ツ)_/¯

delicate portal
#

Well I'll delete it then

#

I'm not interesting in the modding part, I put that for context

#

I'm interested in the Unity specific loading part.

#

Like creating and assetbundle, and then loading the .anim from that

#

Or Resources.Load somehow?

pure drift
#

does anybody know why i cant drag enemy bullet position into the enemy shooting point in the enemy parent prefab it worked i cant get it to work no matter what i did using online tutorials

rocky canyon
#

b/c you can't drag scene objects into a prefab

delicate portal
rocky canyon
delicate portal
#

Your explanation's better SpΔwn

pure drift
#

thank you guys i will take a look at that

queen adder
#

I have a little Grid-Based-Game, and want to add a little Shopsystem, where the player can buy objects and place them on the grid. I wonder is there a kind of await return. The simple breakdown would be, Button-Press -> [ShopScript}triggers buyObjects function ->(funtion "paused" until player picked tile)Player can selected Tile on Grid -> [TileScript]This (Grid)Tile set a Varible in [ShopScript] -> buyObject funtion continues (either if Varible X != null after retrun). Do you have a idea what i should look up on google to do such thing, is async teh answer?

rich adder
queen adder
#

okay i look that up, thanks

rich adder
# queen adder okay i look that up, thanks

more or less a rough example

public class Purchase : MonoBehaviour
{
    [SerializeField] private TilePicker tilePicker;
    public void InitilizePurchase(){
        //stuff
        //open buy menu 
        tilePicker.OnTilePicked += OnTilePicked;
    }
    private void OnTilePicked(Vector3 pos, MyTile tile){
        tilePicker.OnTilePicked -= OnTilePicked;
        //do something based on tile?
    }
}

public class TilePicker : MonoBehaviour
{
    public event Action<Vector3, MyTile> OnTilePicked;
    //probably needsto be with in update with a bool you toggle when purchase needed or other way to detect input / selection
    private void PickingTileLogic(){
        if (Input.GetMouseButtonDown(0)){
            var tilePos = Grid.WorldToCell(worldPos);
            var tile = Tilemap.GetTile<MyTile>(tilePos);
            if (tile){
                OnTilePicked?.Invoke(tilePos, tile);
            }
        }
    }
}```
#

of needs null checks and other stuff but should get the idea going

dusk musk
#

Hey folks! Despite my adding a Rigibody component with Constraints to my camera, when controlling it I can still do movement I shouldn't be able to. Can someone review my video and offer advice? What I want to achieve is to move along a flat horizontale plane using WASD, and use the camera to aim at things - but never "fly" towards where I'm aiming. Thank you!

languid gyro
#

here's this code for beginners before creating a Button To Exit The Game

hexed terrace
#

that's not good code - why are you sharing that

naive pawn
#

or actually, rather; you should probably have the camera as a child so it can pitch freely, separate from the player

verbal dome
dusk musk
# naive pawn how are you moving the camera?

Hey! I was originally using this:

    void Update()
    {
        //Get player input
        horizontalInput = Input.GetAxis("Horizontal");
        forwardInput = Input.GetAxis("Vertical");

        //Moves the player
        transform.Translate(Vector3.forward * forwardInput * speed * Time.deltaTime);
        transform.Translate(Vector3.right * horizontalInput * speed * Time.deltaTime);
    }```

But now I'm looking into a Rigidbody and adding force. Which works better, but I have to now figure out how to properly slow down.
#

So now I'm using this

        //Get player input
        forwardInput = Input.GetAxis("Vertical");

        //Movement
        playerRigidBody.AddRelativeForce(Vector3.forward * forwardInput * speed, ForceMode.Force);
languid gyro
#

hold on i gotta fix that

hexed terrace
#

nah. just delete it

#

no one needs or wants it

languid gyro
#

ok fine

naive pawn
naive pawn
dusk musk
verbal dome
# dusk musk So now I'm using this ```cs //Get player input forwardInput = In...

Here's a fun way of doing forces:cs Vector3 targetVel = /* your desired move velocity */ Vector3 diffToTargetVel = targetVel - rb.velocity; rb.AddForce(diffToTargetVel * accelerationMult);

You can adjust the "stiffness" by adjusting accelerationMult
The idea behind this is that you only add the force that is needed to reach the current target velocity

verbal dome
#

Linear drag is also an option yeah. Try stuff out

dusk musk
naive pawn
#

...are you trying to implement a jump?

#

just say so lol

#

you have the check for detecting a space press

#

just make it jump/animate
there's quite direct methods for both, have you tried researching them?

polar acorn
#

So... you press space, and you teleport this object to 0, 0.1164255, 0?

#

Also, put an f at the end instead of casting to float

#

Huh, they disappeared

acoustic sequoia
#

can someone help me convert this coroutine to a async await Task function?

  {
    float et = 0;
    int i = 0;

    List<Coroutine> routines = new();
    while (i <= diceComponents.Length)
    {
      et += Time.deltaTime / iterationDuration;
      if (et >= iterationDuration)
      {
        Coroutine r = MoveAllDice(diceComponents[i].transform, duration);
        routines.Add(r);
        i++;
        et = 0;
      };

      if (i >= diceComponents.Length) break;

      yield return null;
    }
    yield return null;
  }```
tough sundial
#

Hey. I’m trying to add the text (TMP) to the question txt.

#

I tried sending the QuizManager over to the “Question Txt”, but it’s not working.

slender nymph
#

your variable type is incorrect. your variable expects a legacy Text object, but you are trying to assign a TMP_Text object to it

steep rose
tough sundial
polar acorn
slender nymph
tough sundial
slender nymph
#

do you know what a variable is?

polar acorn
steep rose
tall glen
#

Guys i am using playerprefab to save data i want to save data for scene 1 when i go to scene 2 and when i come back to scene 1 it loads

slender nymph
#

don't crosspost

onyx ledge
#

not going to lie i don't understand C# att all, can someone maby help me out? i just want a quick walk tru.

polar acorn
onyx ledge
#

ohh realy? ty did not know that. going to check that out. ty for helping me the right way

queen adder
onyx ledge
#

ty i will try all of this, hopefully i get somhere in unity. ty for you help

queen adder
tough sundial
#

I’m using 2d.

#

Universal 2d Core.

tough sundial
#

My apologies, I’m doing a project my professor assigned me to do. I got everything right, but all I need to do is change the variable.

slender nymph
#

and you know what a variable is, yes?

tough sundial
#

Sadly, no. 🙁

#

I just learn the stuff from YouTube.

slender nymph
#

there are beginner c# courses pinned in this channel. perhaps start there if you didn't pay attention in class

tough sundial
#

I got it!

#

Thank you.

slender nymph
#

you should still go through the beginner courses if you plan to continue using c#

rapid locust
#

I have a problem with a USB joystick; it works in the editor and Windows build, but when I build it for Android, it stops working. I am using the new input system.

proud vigil
#

im super sorry if this is the wrong Channel, but i got no clue where to put it: my Game Scene - even when everything is empty - can only reach 15 fps at max... i never had that before, any idea why? Target Framerate is 60fps and "Gfx.WaitForPresentOnGfxThread" takes like 50% of the time per frame

teal viper
rare basin
#
public override void PerformAction(Character caster, Character target)
{
    base.PerformAction(caster, target);
    caster.AnimationController.PlayAnimation(animationStateName);
    
    caster.StartCoroutine(WaitUntilAnimationFinish(caster));
}

private IEnumerator WaitUntilAnimationFinish(Character caster)
{
  yield return new WaitForEndOfFrame();
  
  var stateInfo = caster.AnimationController.GetCurrentAnimatorStateInfo();
  
  while (true)
  {
      Debug.Log($"NormalizedTime: {stateInfo.normalizedTime}");
      
      if (stateInfo.IsName(animationStateName) && stateInfo.normalizedTime >= 1f)
      {
          actionFinished = true;
          yield break;
      }
      yield return null;
  }
}

why is the normalizedTime always printing 0, even when the animation is playing properly? That results in actionFinished never set to be true. I want to set it to true after my animation finish

#
public AnimatorStateInfo GetCurrentAnimatorStateInfo()
{
    return _animator.GetCurrentAnimatorStateInfo(0);
}
proud vigil
#

thats what my profile says, im struggeling to read that clear tbh, never used it before

#

found it... my nvidi control panel screwed EVERYTHING. even with it beeing set to 50fps its locked to 15 for magical reasons. i set it now to 250 and i get clean 125 frames (no clue why its halved but idc... works)

teal viper
narrow frost
#

How do I override height settings on an object that spawns on a spline?

#

by default, when attached to the spline, my train is spawing below the track

#

when I change the train position to +10 on the Transform properties (of the train itself) then it looks correct BUT when I press play it re-takes the variable from the spline and goes back under it. Any ideas?

frosty hound
#

Where is the pivot of the train?

narrow frost
#

I don't know what that is, I'm a complete noob 😕

frozen pebble
frosty hound
#

The point in space that the model uses at its position.

narrow frost
frosty hound
#

The issue is that your pivot on the object isn't at the bottom of the train. That's the point that is aligning with the spline.

#

But if you want to hack around it, when you position the object when evaluating the spline, just add the height offset to it as well

narrow frost
frosty hound
#

Code

narrow frost
#

or how to change the pivot point?

#

ah 😕

frosty hound
#

In a modeling program such as Blender

narrow frost
#

ugh

#

seems so bizarre for something so simple

frosty hound
#

Alternatively, you can create an empty object and put your train in there and offset the train inside.

#

Then use the root object on the spline

narrow frost
#

Okay, that makes more sense to me I will look at that

frosty hound
#

Stop crosspointing, thanks.

valid violet
#

@tall glen you can save data inside player prefs or in file (if u want save that data on disk) or you can use DontDestroyOnLoad method

tall glen
stuck palm
#

if playerprefs cant find anything, does it throw an error?

tall glen
#

no

zenith cypress
tall glen
#

private void OnSceneUnloaded(Scene scene)
{
// Save the game data before leaving the scene
SaveGameData();

#

it looks something like that

#

but i want it to load and save between switching scenes

valid violet
#

You can use OnApplicationQuit for example

tall glen
valid violet
#

Or just in method before you are loading scene

tall glen
#

but i want berween scenes

#

cause i use scenes as cutscenes

polar acorn
#

Don't use PlayerPrefs to pass data between scenes, use a DontDestroyOnLoad object

valid violet
#

you should have public void LoadScene(int sceneId){Save(); LoadScene(sceneId); }

polar acorn
#

PlayerPrefs leaves its data behind in the system's registry, storing a lot of data in there means a big chunk of space your average user probably won't know to get rid of

tall glen
#

its the simplest way

#

player pref

polar acorn
#

Imagine if simply playing a unity game tied up a gigabyte of your hard drive without telling you that stuck around even after you uninstalled the game

tall glen
#

cause i cant find a youtube vid thats acctually good

valid violet
#

Don't destroy on load will make your object undestroyable when you change a scene it will exist with data u set in previours scene

polar acorn
#

It's unlikely you'll store that much data, but you still shouldn't. Player prefs should be for exactly that, preferences. Things like graphics settings, window size, etc.

tall glen
polar acorn
#

If you need data to go across scenes, better to just put that data on a game object and pass that entire object between scenes

tall glen
#

no i dont want it to go actoss scnes

polar acorn
#

Doesn't require writing anything to your user's OS Registry that way

tall glen
#

i want it to stay

#

so when scene 2 cutscene is done

polar acorn
tall glen
#

it can still be same

polar acorn
tall glen
#

so U go do the motrher and brother mission

#

so i add this and itl work?

tall glen
#

but it all didnt work

#

this is the only one i acctually understood

teal viper
#

If you just need to keep some data between the scenes,do what digiholic recommended.

tall glen
#

and start all over again

valid violet
#

Sorry Im blind your code is fine you have already SaveGameData in correct place inside SwitchScene()

tall glen
#

and its a loop

icy crag
#

there might be a bug in your code for the next level

tall glen
teal viper
#

@tall glen
Probably because there's an issue with your saving/loading logic. Or just the game flow logic in general.🤷‍♂️

As for what Digiholic recommended, there are plenty of videos on that:

tall glen
#

watched most of them

#

i coudnt understand

#

damn

#

its 3 am

teal viper
#

Then start simpler. Did you go over the beginner pathways on unity !learn?

eternal falconBOT
#

:teacher: Unity Learn ↗

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

teal viper
#

If you don't k ow the basics, you're gonna keep on struggling.

#

Do proper learning before continuing your project.

tall glen
#

i just need to do this then ima publish the demo

teal viper
#

No

steep rose
icy crag
#

I'm sure P-A-I-N knows the basics

tall glen
#

thats why i choose unity

#

cause im familiar

#

also i learned some of c#

#

the one i sended was called a method

valid violet
#

Check the LoadGameData just debug it if it will be loaded in first scene in right place or it is rewrited somewhere to starting values when you are loading first scene

tall glen
#

im gonna just watch a vid

icy crag
tall glen
#

like digiholic said

icy crag
#

i do that all the time

polar acorn
tall glen
#

like in timeline i put activation track

valid violet
#

You can have problem when scene rewrite data to default and saving it in wrong place so you LoadSaves after it was set to default values

tall glen
#

OH

#

but how do i do that

icy crag
tall glen
#

cause there will be 2 cameras

#

wait i record

#

here

#

dont mind colliders

#

theyre easy

#

i fix later

#

@icy crag @polar acorn @valid violet

#

@teal viper

supple salmon
tall glen
#

nvm the error

#

its nothing\

worthy veldt
#

im trying to rebind controls using PerformInteractiveRebinding , however I set up reference only for InputBinding, how do I get InputAction and the binding index from there ?

supple salmon
# tall glen

Hmm they are not the most recent log statements from your video. Do you get your debug log statement ‘Player reference is null. Cannot load position.’ logged while changing back to your first scene?

worthy veldt
pure drift
#

does anybody know how i could make it so that the enemy spawns properly instead of in a huge rectangle i tried implementing some things from online but i couldnt get it to work. im assuming its to do something with the frames per second and thats why its spawning alot but im not sure what to do about it

thick merlin
#

Trying to following a youtube guide but I'm already stuck. I can't find the sprite mode and pixels to units option anywhere? Anyone know where

#

confused, why cant i see pixels to units

steep rose
eternal falconBOT
slender nymph
thick merlin
#

ah i see my bad, thanks for the help

pure drift
#

!code

eternal falconBOT
faint osprey
#
    {
        if(m_CanGrapple)
        {
            m_CanGrapple = false;
            player.GetComponent<LineRenderer>().enabled = true;
            player.GetComponent<LineRenderer>().SetPosition(0, player.transform.position);
            m_rb.AddForce(gameObject.transform.right * m_grappleSpeed, ForceMode2D.Impulse);
        }
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        m_rb.freezeRotation = true;
        m_rb.constraints = RigidbodyConstraints2D.FreezePosition;
        player.GetComponent<LineRenderer>().SetPosition(1, gameObject.transform.position);
    }```

im using a line render to show a connection between my player and my grappling hook however when i first draw it it draws a line randomly to the middle of the screen and then snaps back to the correct place does anyone know why this might happen
pure drift
steep rose
#

And please use the bot for code formatting.

pure drift
#

sorry im having a hard time with the pasting service

#

yeah somethings up with my cookies sorry for the troubles ill try again a different day

sour nimbus
#

Does anyone know a way to prevent this from happening? What happens is that when I rotate the sprite it moves and doesn't stay in the same position. I am using spriteRenderer.flipX to rotate it

slender nymph
#

that means that the sprite's appearance is not centered on its pivot point

sour nimbus
#

Do you mean changin center for pivot?

slender nymph
#

no, i mean the actual sprite's pivot point in the sprite editor

sour nimbus
#

In the sprite editor it is set so that it is in the center

slender nymph
#

show it

sour nimbus
slender nymph
#

okay, now actually look at where the pivot point is in relation to the image

sour nimbus
slender nymph
#

so you see that circle in the center? that's the pivot point. what do you think will happen when you mirror that image along its pivot point

sour nimbus
#

I assume it happens because the edges of the sprite are larger than the sprite itself, but I put it that way because when using larger animations like hitting it looked like it was moving while doing the animation, I don't know if you understand. Is there a way to prevent that from happening so i can set the borders normal?

slender nymph
#

you need to adjust its pivot point so that the sprites always line up correctly

polar acorn
sour nimbus
#

I solved it, thank you

final sluice
#

So after I add this single line of code, the ball fall down extremely slow, what might be the reason for this ?

slender nymph
#

you're setting its Y velocity to 0 which is resetting gravity

final sluice
#

oh

#

crap

#

Tks

slender nymph
#

since you're probably using unity 6, and this is clearly 2d, just assign the linearVelocityX or whatever that property is now called

final sluice
#

Do I need to create a new vector to assign it ?

meager gust
#

wouldn't that be the Y axis

naive pawn
slender nymph
final sluice
#

tks

meager gust
naive pawn
#

which is what you don't want to do

meager gust
#

yes...

slender nymph
#

right so they need to only assign to the linear x velocity, not both axes

#

2d has properties to assign each axis individually (in unity 6)

meager gust
#

ah, didn't know that was possible with 2d

ember tangle
#

If anyone else had this problem, the issue is that Unity C# does not support Func<> and you need to use Action<> instead.

slender nymph
#

unity absolutely does support Func

north kiln
#

There is nothing about Unity that stops you from using Func

cosmic dagger
#

were you trying to return a value?

slender nymph
#

it sounds like you probably had a method that returned void with a GameObject parameter, which is indeed an Action<GameObject>, a Func<GameObject> would be a method with no parameters that returns a GameObject

cosmic dagger
#

you probably used the incorrect delegate and received an error . . .

ember tangle
#

Well I tried Func<> several ways with no success, and Action<> works perfectly.

slender nymph
#

show what you were actually trying to pass

cosmic dagger
ember tangle
#
{
    pointer = new PointerEventData(eventSystem);
    pointer.position = Input.mousePosition;

    //Create a list of Raycast Results
    List<RaycastResult> results = new List<RaycastResult>();

    //Raycast using the Graphics Raycaster and mouse click position
    raycaster.Raycast(pointer, results);

    //For every result returned, output the name of the GameObject on the Canvas hit by the Ray
    foreach (var result in results)
    {
        if (result.gameObject.CompareTag("ItemPane"))
        {
            function(ItemPane.GetPaneFromObject(result.gameObject));
        }
    }
}```
cosmic dagger
#

Action is the typical/normal way to pass a method . . .

slender nymph
north kiln
#

If you just had the above code and instead had Func then you just misunderstand what Func does

ember tangle
#

Very likely

cosmic dagger
#

i would've looked up Action and Func to see what they are/do and their differences . . .

ember tangle
#

again, very likely im wrong but my code works and thats enough for me

slender nymph
#

Func has a return type other than void. Action has a return type of void

final sluice
#

Is the physics engine stable ? Do they have a way to calculate a fixed time between updates or they rely on my hardwares ?

north kiln
#

What do you mean calculate a fixed time? Fixed Update is advanced by a fixed time, there's nothing to calculate

cosmic dagger
#

if it wasn't stable, i don't think they'd have much of an engine for anyone to use . . .

ivory bobcat
# ember tangle I read several stack overflow questions claiming that Func<> works as a function...

Encapsulates a method that has a single parameter and does not return a value.
https://learn.microsoft.com/en-us/dotnet/api/system.action-1?view=net-9.0
Encapsulates a method that has no parameters and returns a value of the type specified by the TResult parameter.
https://learn.microsoft.com/en-us/dotnet/api/system.func-1?view=net-9.0
The function variation shown above simply does not take an argument but the other variations do.
Action and Funcs differs in that Funcs always expects something to be returned.

cosmic dagger
#

also, they already calculate a fixed time between frames . . .

final sluice
north kiln
final sluice
north kiln
#

not sure where my arrowheads have gone, but whatever 😄

teal viper
#

Vertx shameless self promotion 😛

cosmic dagger
#

nah, this is just godly awesomeness . . .

#

they've seen people ask the same questions and problems more than anyone. it makes sense to have a document for all this stuff . . .

timber tide
#

dont need to think too hard if you just shove everything into fixed thinksmart

cosmic dagger
#

heck, i created one when i first started unity for beginners . . .

final sluice
timber tide
#

It's a joke, but a good way to think of it is you're more likely to break stuff putting stuff that belongs in fixed update into update

#

as far as unity physics (rigidbody) modules go

#

Stuff that belongs in update -> Polling input, and lerping visuals

#

If you use Unity's (now) standard input then you can cut out the input polling, and if you download a tweening library (or coroutines) you can use that over lerping in update

molten dock
#

how do check if a variable is worth more than another by a certain amount

tardy kelp
#

Hey I'm trying to make a boomer shooter where the player's gun is a 2d image and animation. would I add a canvas to the player and have that run the gun animation?

#

or would I do something else?

teal viper
cosmic dagger
light briar
teal viper
tardy kelp
#

would I have it shown in the camera?

timber tide
tardy kelp
#

gooootcha

cosmic dagger
tardy kelp
#

wait a second camera?

molten dock
cosmic dagger
light briar
molten dock
#

id like to check if the difference between two variables is equal to or above a certain amount :)

cosmic dagger
#

You could be right. I don't know, so I'm covering all bases . . .

teal viper
#

Just a - b > c would be enough

light briar
#

True true

cosmic dagger
molten dock
#

why are we doing minuses

cosmic dagger
#

That gives you the difference . . .

molten dock
#

oh yeah lol i see

#

alright thanks

final sluice
#

I want to make a ball jump while it's on ground, can someone give me a direction in what should I do ?

timber tide
#

You should search around for tutorials depending if you want to use unity's rigidbody physics, or making a kinematic ball where you control the bounce more directly

final sluice
#

So I have this code, the horizontal movement is fine but the ball don't go up all the time when I press w , why is that ?

teal viper
final sluice
final sluice
#

Do you guys use the new input manager ? Is it necessary for a professional job ?

charred spoke
sour nimbus
#

How can I make the objects appear above a panel in unity 2D?

delicate portal
#

Hey I'm using assembly definitions, but I referenced assembly2 to assembly1, but I cannot use the classes in assembly2's scripts in script1 but I can use assembly1's scripts in script2. How can I fix this without circular reference?

charred spoke
delicate portal
#

I need them to reference each other

charred spoke
#

You cant do that

#

Consider restructuring your code into 3 assemblies.

languid spire
#

only way to do that is by using Reflection

delicate portal
charred spoke
#

Circular references are bad design that should be avoided

charred spoke
delicate portal
#

Thanks

final sluice
#

What movement methods should I use for a moving platform ?

#

physic based velocity changing or transform.translate/transform.position

delicate portal
#

I'd just use parenting

delicate portal
#

Or vector2

teal viper
queen adder
#

How do i make it so that everytime i create a script inside a folder, the script body will automatically be inside specific namespace ? Something like assembly definition root namespace, but i dont want to use assembly definition for that

delicate portal
#

Just type it in

queen adder
#

I mean, i wonder if there is automatic way to do it

#

Just to make my hand less tiring

delicate portal
#

There is a way ye

queen adder
#

Ok thanks i'll read that

queen adder
final sluice
#

Why do I need to multiply a vector with time.deltatime if it's in fixedupdate ? ( this is taken from the unity manual )

queen adder
#

That is not what i'm looking for

delicate portal
#

I mean, one time will come when you'll have to use assembly definitions, its good design

queen adder
#

i want to avoid asmdef because the folder is already inside an asmdef and i dont know how nested asmdef work

delicate portal
delicate portal
#

I'm that lazy

queen adder
#

welp, looks like manual is the way then

delicate portal
#

For now, but you can give it a search

north kiln
north kiln
final sluice
queen adder
#

Fixed update rate is the rate at which fixed update is invoked

north kiln
final sluice
north kiln
#

Not particularly, your speed might not be in m/s in this specific case. Many other cases are multiplied internally so multiplying again would be bad. It really depends what API you use

hexed terrace
burnt vapor
#

For example, make a third assembly that is shared between the two

#

In cases where you hook content onto another assembly you can have assembly 1 reference interfaces which assembly 2 then hooks onto through extension methods provided by assembly 1

#

But most importantly, circular references usually mean that you are trying to decouple too heavily because they both depend one achother

#

So optimally it should just be 1 assembly if there's no logical way to have a shared assembly, or hooking

#

For example, if it's just general utils used then you might aswell make an assembly for those specifically

#

It would help if you explain your use case more clearly so a proper solution can be given

#

And pls don't use Reflection like SteveSmith mentioned. You should not have to use Reflection and it is going to look horrible. The only case would possible when you involve attributes to hook onto content

#

Literally have this issue in a project at work where they have two projects and they just use reflection now to get content. It's impossible to debug or unhook now and I can't use the project because of it

past spindle
#

Can you declare a private variable that is the name of another object?

languid spire
#

yes as long as they are not in the same scope

past spindle
#

Can you elaborate?

languid spire
#

do you knoow what scope is?

past spindle
#

Sort of. I have a page open that I'm reading on Variable scopes (unity docs).

languid spire
#

a matched set of braces { } is a scope
a variable must be unique within a scope

past spindle
#

ok

languid spire
#

this is basic C# so you should be using the C# docs not the Unity ones

past spindle
#

ok

past spindle
#

I've been trying the following line of code and variations of it, but I keep getting errors. Is there another way to go about this or do I just need to tweak something?

private string shapeClassF = gameObject.GetComponent(name) ;

placid oxide
#

any idea why I get the same coordinate in the debug regardless of the position of the card?(same position for every card spawned and set to grid)

languid spire
past spindle
hexed terrace
#

You don't get the name of a component with GetComponent<T>().. you get the component

languid spire
steep rose
past spindle
#

Yes, I mean the name of the object