#💻┃code-beginner

1 messages · Page 281 of 1

buoyant knot
#

correct

#

and if you don’t, the two systems won’t work with each other

ornate lynx
#

yeah yeah understood

buoyant knot
#

you’ll either give multiple Physics invocations before one physics sim, or you’ll miss the frames for input from Input

#

if you don’t split update vs fixed update

ornate lynx
#

i get it now

visual hedge
#

Problem: Built a build with 1600x900 resolution
Built next build with 1920x1080. And it still launches as 1600x900 how to fix?

ornate lynx
#

though lets say i detected that the player released one of the arrow keys, to stop the character from slipping i'm gonna add a force opposite to the force applied for meving the player. if i do this in FixedUpdate, using impulse, it's still gonna happen every fixed frame right?

tired junco
#

Hey one question:

if i call a function in Update() Method is it possible that Update() is called again while i run the Method that i called in Update is still running? So will Update wait for a method that is called there or will it just call it every frame no matter what other method i called (I hope that this is somewhat understandable >:)

buoyant knot
#

you need the if statement to make a check every frame

buoyant knot
#

and you don’t want to set up recursion with Update

#

you would only want this with a custom method where you control arguments to know it will end

dusk musk
#

Hey everyone. I have this error, which I think means I didn't drag an object into my Inspector somewhere. But that doesn't appear to be the case.

Menu.Update () (at Assets/Scripts/Menu.cs:23)```

Can someone advise me on what to do?
#

This is what my Unity looks like.

short hazel
buoyant knot
#

Menu.cs line 23 has an object that is null

#

that your code needs to not be null to function

dusk musk
#

Thanks both @short hazel and @buoyant knot. The error only appears when I go from Scene 0 to Scene 1. The Menu script is only attached to an object in Scene 0. It does not exist in Scene 1. Could that be the casue of the error? How do I go and prevent it? Appreciated! 🙏

short hazel
#

Check line 23 and see what could be null on that line

#

From there you can investigate the causes

dusk musk
buoyant knot
#

that should be a serialized field

short hazel
#

Well yes, if the input field is not also moved to the other scene, it gets destroyed when the scene unloads

dusk musk
short hazel
#

The script is on an object in the other scene

dusk musk
languid spire
short hazel
dusk musk
dusk musk
gray carbon
#

Can someone help? I wrote this code using the new input system. But at some random intervals, my jump won't seem to work.

public void Jump(InputAction.CallbackContext value)
{
if (value.performed)
{
// Check if the character is grounded
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);

        // If grounded, apply jump force
        if (isGrounded)
        {
            rb.velocity = new Vector2(rb.velocity.x, vertical); // Set vertical velocity directly for jump
        }
    }
    else if (value.canceled && rb.velocity.y > 0f)
    {
        // If jump button is released and character is still going up, reduce vertical velocity
        rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
    }
}
summer stump
timber tide
#

I suggest logging your session and make sure your states are being set correctly.

queen adder
#

what other callback I should use to ensure my savesystem will happen

summer stump
#

I also recommend just setting your desire to jump in the callback and handle things in fixedUpdate

timber tide
gray carbon
queen adder
gray carbon
visual hedge
#

what is it that cone thing that follows my player? How do I get rid of that artifact?

tall delta
visual hedge
wooden vine
#

Hi, I am a new Unity user. I know that putting a collider for my mesh would make it stop from falling through the floor. I tried that but it still kept falling through. I also added another sphere next to my character with a rigidbody and a collider and notice how that didn't fall though but my character did.

tall delta
visual hedge
#

there's no lighsource attached to a players GO

tall delta
tall delta
summer stump
# gray carbon ahhh i set up the physics in fixedUpdate?

Physics should be handled in fixed update, yes. Now, in that video, is the issue still happening? I saw a couple times it seemed like you expected the jump to happen sooner?

You might want to use value.started instead of value.performed

wooden vine
wooden vine
tall delta
# visual hedge still no

I'm not trying to be mean, but I'm gonna need to see an image of all 3 inspectors before I believe you 😅

visual hedge
tall delta
#

aighty, then you figure it out, gl 🙂

ivory bobcat
gray carbon
visual hedge
ivory bobcat
visual hedge
#

whatever I change about my only lightsource, this artifact stays

summer stump
ivory bobcat
#

If so, that light isn't the culprit

visual hedge
#

if there's no light, that thing goes away, sure. But that would onyl prove the point that it's something with terrain material?

gray carbon
# summer stump Well, you only do the ground check when the Jump action callback is sent. I reco...

private void FixedUpdate()
{
// Check if the character is grounded
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);

    // If grounded and shouldJump is true, apply jump force
    if (isGrounded && shouldJump)
    {
        rb.velocity = new Vector2(rb.velocity.x, vertical); // Set vertical velocity directly for jump
        shouldJump = false; // Reset the flag after jumping
    }
}

public void Jump(InputAction.CallbackContext value)
{
if (value.started)
{
shouldJump = true; // Set flag to indicate a jump should occur
}
}

I have, but sometimes it does not record the collision between the player and the ground

ivory bobcat
#

What is this cone thing that follows my player?
So you've identified that the cone following your player is from your light source. How you orientate your light will determine what kind of shape you'll get and how you modify your material would determine the intensity etc

tall delta
quick ruin
#

theres no tab for this - how do i get my convex mesh to stick to the mesh edges

summer stump
tall delta
wooden vine
summer stump
#

Is that collider on the same object causing the gravity?
Looked like the root object was left behind on the ground, and only the child model fell?

wooden vine
#

one is the parent and the other is the child

tall delta
visual hedge
gray carbon
#

Here it doesn't detect the collision anymore

summer stump
#

Alright, clearly is the grounded...
Can you show the groundCheck position child object?

gray carbon
ivory bobcat
#

Where did you place the log statement?

gray carbon
#

private void FixedUpdate()
{
// Check if the character is grounded
isGrounded = Physics2D.OverlapCircle(groundCheck.position, 0.2f, groundLayer);

    if (isGrounded && shouldJump)
    {
        rb.velocity = new Vector2(rb.velocity.x, vertical);
        shouldJump = false; 
    }
    else
    {
        Debug.Log("isGrounded: " + isGrounded + ", shouldJump: " + shouldJump);
    }
}
wintry quarry
summer stump
#

Well... yeah I saw you jump from a platform... so I guess they are

#

May as well check 🤷‍♂️
The groundcheck object looks like in the right spot

gray carbon
#

I have checked everything but I can't seem to understand where the problem is coming from

#

Thank you for your help. I am going to restart the project and try to trace my mistake

ivory bobcat
ivory bobcat
#

Seems to be fine with the floor and upper platform but it may just be a coincidence.

wooden vine
#

this was a character controller in the unity asset store

#

it worked before

#

but when I switched scenes for a while and went back to it, this happened

summer stump
wooden vine
ivory bobcat
# wooden vine

Assuming the floor and player have got the proper components, what's in the player input script?

#

Are you perhaps moving with the Transform component or some other means?

wooden vine
#

This whole thing was in the Unity asset store

#

It worked a few days ago

#

but when I reopened it, it doesn't work

wooden vine
ivory bobcat
#

Maybe show the inspector for the floor if you haven't already or relink to it.

wooden vine
#

oh

#

ok

ivory bobcat
wooden vine
#

In the original video that I sent, I added a sphere with rigid body and it didn't fall though the floor like the character

ivory bobcat
#

Character Controller should come with a built in default hidden capsule collider already so no extra colliders should be necessary

#

Can you show the collision matrix?

tall delta
#

could it be this thing, just yeeting the player through the floor collider? what happens if you set the strength to 0?
from the video it looks like there is a massive jerk down right as the game starts.

wooden vine
ivory bobcat
#

The floor isn't assigned a layer so maybe you're pushing it downwards UnityChanThink

ivory bobcat
#

Unsure if push direction only applies to horizontal or any contact

wooden vine
#

oh

wooden vine
tall delta
wooden vine
ivory bobcat
summer stump
ivory bobcat
tall delta
#

not the highest framerate in the world, but you go from this, to that in one frame on the video. what happens if you just place the player really high up?

wooden vine
#

I did

#

Should I create a new video showing the results

summer stump
# wooden vine I did

So you placed it in the editor, but the first frame of gameplay seems to be SETTING the position lower

#

Do you have code setting the position?

wooden vine
#

It fell to the ground and when it touched the ground it was stuck for a second, but then it phased through

wooden vine
tall delta
# wooden vine

well that is wired! looks like it's hitting the ground, the phasing through it

wooden vine
#

Thats odd

tall delta
#

what if you just set this a bit lower?

hexed terrace
#

it'll fall faster

tall delta
#

...a bit higher 🥲

ivory bobcat
#

They probably meant moving the value towards zero 😅

tall delta
#

like -5 or something

wooden vine
#

a bit higher made him fall slow mo

#

but he still went through

#

😦

hexed terrace
#

gravity isnt going to stop it falling through

#

check the collider isn't being disabled

wooden vine
#

Ok

wooden vine
ivory bobcat
wooden vine
#

but I attached a sphere next to the character and when the both fall down, the sphere actually hits the floor but the character phases through. But when I make the sphere a child of the character, they both phase through the floor

hexed terrace
#

something is doing movement without physics, possibly

#

with a ground check that's failing, not setup correctly?

indigo crescent
#

if it was a rigidbody on the player then I'd say change the collision detection to continuous but looks like that player has a charactercontroller component

ivory bobcat
#

Try unchecking the player input and third person character controller component boxes - disable the two components.

wooden vine
indigo crescent
#

darn

#

you sure you haven't got something in the script disabling colliders the player touches?

wooden vine
#

Its wierd that it worked before but after i switched scenes and back, this happens

indigo crescent
#

okay that's weird

#

have you tried restarting unity?

wooden vine
#

yea

ivory bobcat
indigo crescent
#

turning it off and on again normally helps

wooden vine
#

Is it possible that a change in project settings resulted in this

indigo crescent
hexed terrace
tall delta
indigo crescent
#

it would just ignore it completely

hexed terrace
#

yep

ivory bobcat
#

It animated hitting the floor so likely something else has happened and apparently it's fine with rb and a regular collider

indigo crescent
#

maybe the collider is changing at runtime or something

tall delta
ivory bobcat
hexed terrace
#

It's the Unity asset, so it's not code related.

Remove the asset and re-import it

wooden vine
#

Ok

wooden vine
indigo crescent
#

that should work

tall delta
# wooden vine Ok

if that doesn't work, can you send an image of the collision matrix?

wooden vine
#

sure

#

one min

#

How do I remove an asset

indigo crescent
#

get into the package manager

hexed terrace
#

find the folder and press delete

hexed terrace
indigo crescent
#

wait you can't remove it from the package manager?

#

you can certainly import it from there

#

ah yes

wooden vine
#

I added some files to the folder so I am going to relocate them before deleting

indigo crescent
#

my bad, I haven't imported an asset to unity in a long time xD

hexed terrace
indigo crescent
#

yeah

hexed terrace
#

If they have code in, that references code in the asset.. you will get compilation errors after deleting, obviously

dusk musk
#

@short hazel @swift crag @buoyant knot Thanks all for your help today. I managed to create my working scripts, and can now succesfully input a name on Scene 0, and show it in the TextMeshPro that's displaying my score on Scene 1.

indigo crescent
#

darn

swift crag
#

Most assets from the asset store will just be a .unitypackage (yes, great names here) that puts files in your Assets folder

indigo crescent
indigo crescent
wooden vine
languid spire
#

bear in mind .unitypackage existed long before the package manager did

wooden vine
#

I used another asset for another scene and did another scene manually. Is it possible that the one I used an asset on messed with the physics

ivory bobcat
#

Your player was a part of the placement layer whereas the ground was set to the default layer

ivory bobcat
# wooden vine

Placement layer seems to be unchecked with all other layers

#

Maybe set the player to the default layer instead of the placement layer?

wooden vine
#

Is there any boxes I need to check

ivory bobcat
wooden vine
#

Thank you!

#

that worked for me

wooden vine
wooden vine
#

In this clip, I only clicked spacebar once

ivory bobcat
#

These aren't really coding questions so it'd be more appropriate to ask them in #💻┃unity-talk
You'll get more awareness and suggestions. It would also be the proper place to ask for such a question without being off topic. Copy the message to the channel and delete the message here to properly move a message without cross posting.

hexed terrace
#

and make a thread

wooden vine
#

Oh Ok thanks

queen adder
#

My car interaction:
{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{{
using UnityEngine;

public class CarInteraction : MonoBehaviour
{
public GameObject player;
public GameObject carCamera;
public GameObject playerCamera;
public GameObject exitPoint;
public CarController carController;
public FirstPersonController playerMovement;

private bool isPlayerInside = false;

private void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player") && !isPlayerInside && Input.GetKeyDown(KeyCode.E))
    {
        EnterCar();
    }
}

private void OnTriggerExit(Collider other)
{
    if (other.CompareTag("Player") && isPlayerInside && Input.GetKey(KeyCode.E))
    {
        ExitCar();
    }
}

private void EnterCar()
{
    player.SetActive(false);
    playerCamera.SetActive(false);
    carCamera.SetActive(true);
    player.transform.position = transform.position;
    player.transform.parent = transform;
    isPlayerInside = true;
    if (playerMovement != null)
        playerMovement.enabled = false;
    if (carController != null)
        carController.enabled = true;
}

private void ExitCar()
{
    player.transform.position = exitPoint.transform.position;
    player.transform.parent = null;
    player.SetActive(true);
    playerCamera.SetActive(true);
    carCamera.SetActive(false);
    isPlayerInside = false;
    if (playerMovement != null)
        playerMovement.enabled = true;
    if (carController != null)
        carController.enabled = false;
}

}

#

My car Movement:
]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
using UnityEngine;

public class CarController : MonoBehaviour
{
public float speed = 10f;
public float rotationSpeed = 100f;

private void FixedUpdate()
{
    float moveInput = Input.GetAxis("Vertical");
    float turnInput = Input.GetAxis("Horizontal");

    Vector3 movement = transform.forward * moveInput * speed * Time.fixedDeltaTime;
    Quaternion rotation = Quaternion.Euler(0f, turnInput * rotationSpeed * Time.fixedDeltaTime, 0f);

    GetComponent<Rigidbody>().MovePosition(GetComponent<Rigidbody>().position + movement);
    GetComponent<Rigidbody>().MoveRotation(GetComponent<Rigidbody>().rotation * rotation);
}

}

#

When I move my car moves aswell, also I wanna make it so that when I go up to the car and press E ill enter it, and the camera switch to the cars camera, and when I hold down E I exit and my player spawn on my Empty game object: "Exit" Can anyone help?

#

and my car flips alot, is there a way to not make it flip at all but still interact with other stuff?

#

Thank you

#

Ive never code before

eternal falconBOT
summer stump
#

Sorry, should have linked that to you before

queen adder
summer stump
#

When you say "when I move my car moves as well" do you mean when you aren't in the car?

queen adder
summer stump
summer stump
#

Ok one thing, it is VERY unlikely a GetKeyDown event will happen at the same time as the OnTriggerEnter event. You should instead have a bool that tells you that you are close to the car, then handle input in update

#

And yeah, you just read input in the CarMovement script without checking whether you are actually in the car or not

queen adder
#

I am not good with these stuff not sure what you mean

summer stump
#

Either disable that script when not in the car, or do a bool

summer stump
#

Instead make a bool like
bool CloseToCar

And set it true inside the OnTrigger

#

Then in update, if that is true, and you press E, get in the car

#

For movement, you already have a isInsideCar bool

Just check that

if (!carInteraction.isInsideCar) return;
Right at the top of fixedUpdate

queen adder
#

Ok Thank you so much

#

Ima try that in a bit

hexed terrace
#

no, it's not ok to rely on chat gpt.. at all

rocky canyon
#

you mean to showcase ChatGPT's skills 😉

twilit cliff
# rocky canyon you mean to *showcase ChatGPT's skills* 😉

Definitely not, I don't wanna stick to just taking solutions to my issues from gpt all the time, as I come from non CS background and I need to elaborate the concern in my own words and try to get the best solution possible, I'm using any source available...

On the other hand, I find solution not at the every first attempt on gpt, I've got to drill in and get deeper and find the solution at times to get solution to complicated feature implimentation...

I'm also aware that how to Google is a skill and I believe chat gpt helps me in the same way...

vast vessel
#

hey guys, i cant add ne of my monobehaviors to any gameobject.
unity says it has compile errors, but there is nothing in the console, or the VS error list.
what do i do?

rocky canyon
#

thats when people end up coming here.. and saying "whats wrong with my code" and its a dumpster fire

rich adder
vast vessel
#

yes

#

both are Flechette

rich adder
#

try to trigger another compile

#

right click on project folder do Reimport

vast vessel
#

how about just the file itself?

rich adder
#

you can right click anywhere on project folder doesn't matter

vast vessel
#

no errors still

rich adder
#

try adding script again

vast vessel
#

cant add

#

ill reimport all

rich adder
#

alr show the console / class + filename

vast vessel
vast vessel
#

console is empty other then some 'variable is not used' warnings

rich adder
#

hmm are u sure errors aren't collapsed in console window ?

vast vessel
#

indeed

#

the counter on the top right also says 0

#

the one with the error icon next to it

twilit cliff
# rocky canyon just don't code ur entire code-base from snippets of ChatGPT.. b/c then when the...

Yes, I'm in the learning process and I'm trying to learn and understand as many concepts as possible during this journey and not in the mood to rush as well...

I break down the game mechanics to bit of chunks and try to get the solution for it on my own based on whatever the knowledge I've gained so far but if it's something new, I'm reaching out gpt to help me out and when the solution works perfectly, I sit down and go through those lines of code to see and understand what it means, how it works, and try to get every bit of knowledge out of it...

I also read that 80% of Senior Dev's find gpt most helpful, yet I'm not blindly gonna take that as final source of solution, I just wanna learn and get better and be job ready, so I'm trying my best in every possible way

rich adder
rocky canyon
#

thats b/c senior dev's have the know-how to spot and error and inform chatgpt of that error so it can re-evaluate the code.. the problem with beginners using chat-gpt is they can't usually spot when its being a dumbass

rich adder
vast vessel
rich adder
#

oki

rocky canyon
#

Relying solely on one resource like me for learning can limit exposure to diverse perspectives, interactive learning experiences, and hands-on practice necessary for comprehensive skill development.

#

straight from ChatGPT's mouth

#

but, its your learning experience.. so if ChatGPT is ur cup of tea, go for it.. just note.. that its against the rules to help you with AI generated code.. soo.. better not run into any bugs 😄

twilit cliff
# rocky canyon thats b/c senior dev's have the know-how to spot and error and inform chatgpt of...

I agree, I'm here expressing out my concerns of using gpt since, I'm trying to figure out the best possible solution for the issues I face but I'm not completely relying on it as said before, my priority is not to use gpt and showcase my projects and when reality hits, feel lost, I don't want that, I wanna learn and get better in anyway possible and land my first job cuz of my hard work, I'm spending a day or two sometimes just to implement one of the simple features in the way it's supposed to work, so I'm here seeking help for better ways of finding solutions if there are than chat gpt

wraith valley
#

I did this harder

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

public class ActivatinggameObjects : MonoBehaviour
{
    // Start is called before the first frame update
    private GameObject gameObject1;
    void Start()
    {
        gameObject1 = gameObject;
    }

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.Tab))
        {
            gameObject1.SetActive(false);
        }
    }
}
rocky canyon
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

wraith valley
#

😄

rocky canyon
#

lmao, facts

wraith valley
rocky canyon
#

it makes no sense

rich adder
#

why are you creating a separate variable for something you already have anyway

wraith valley
rich adder
#

gameObject.SetActive(false)
is sufficent

#

there is no reason to creating another variable to assign itself to it..

#

even the lesson doesn't do that, why would you do it UnityChanThink

wraith valley
rocky canyon
#

lol.. well you did lol

wraith valley
#

I did

#

From small to large

rocky canyon
#

gameObject1 = FindObjectOfType<ActivatinggameObjects>().gameObject;

rich adder
#

na na you're doing it wrong

#

GameObject.Find

#

is better

rocky canyon
#

ahh ofc ofc

twilit cliff
#

Has anyone here played AirXonix PC game that was launched in early 2000?

rich adder
#

ye

#

I played in the arcades cause of being poor

rocky canyon
#

ive played similar games

rich adder
#

actually i played the 90s the 2D versions of them

#

some of them had naked chicks on it xD
as you cut the pieces you reveal more of photo haha

#

was a japanese game

twilit cliff
# rich adder I played in the arcades cause of being poor

I'm trying to build that game and so far, I've come close to getting basic gameplay mechanics and few other stuff, I want to know how to fill the empty space when I enclose it like in this game, not able to find the solution yet

rich adder
#

I been trying to do this in 2D tbh because of nostalgia, haven't really thought about it in a while

#

you basically have to find a way to make your Verticies and create a mesh

twilit cliff
#

Cool

rich adder
#

yea so like each corner you turn , you make a new vert

#

then build the mesh when you completed

twilit cliff
#

What about Raycast and Trail renderer, are they any help to make that feature happen?

rich adder
#

You could use raycasts potentially but you'd have to probably make all your squares single boxes and might kill perfomance

twilit cliff
#

Dang

rocky canyon
#

ya, u could make a big grid system

#

instead of doing vert

rich adder
#

try whatever is easier for you, then optimizing/iterate later

rocky canyon
#

rely on math to fill them in

rich adder
#

I once made a connect 4 game with nothing but raycasts cause it was too annoying to lerp math grid pos, it came out ok

rocky canyon
#

u make a win / lose state?

rich adder
#

yup fully functional, it just raycasts to check matching coins i each direction / diagonal

rocky canyon
#

sounds fluffy

twilit cliff
#

I spent whole day trying implementing some of the features, though I'm not successful upto the point of filling the empty space, I'm happy with today's progress of implementing some features for that game, I'll have it shared with you guys once it's ready if you wanna try and share input?!

spiral rain
#

Hey I am trying to make a flappy bird(ish) style movement system but it behaves very weirdly how can I make a movement system like flappy bird ish or how do I fix it Code:https://hastebin.com/share/buyuyomuve.csharp. Problem: Sometimes doesn't go up

rich adder
#

more likely you get plays with Webgl, i personally dont download any exe 😛

rocky canyon
twilit cliff
rich adder
#

maybe you have more plugins in chrome or something? are you sure its just u or everyone

twilit cliff
#

I've very few plugins and extentions on chrome, a VPN, ad blocker, and another one or two but mostly all of them are disabled all the time

rich adder
rocky canyon
twilit cliff
rich adder
#

that thing chugs

#

🦊 squaa

rocky canyon
spiral rain
twilit cliff
#

How about using Impulse than velocity for flappy, isn't it more suitable compared to velocity?!

Please forgive me for my dumbness if I'm wrong and educate me

rich adder
rocky canyon
spiral rain
rocky canyon
#

then u just need to crank up the force until it does

rich adder
rich adder
twilit cliff
rocky canyon
#

ya, im running 2080ti too

rich adder
rocky canyon
#

^ exe are OP.. just make sure to make ur page look professional with screenshots / video if necessary

#

so it doesn't look like a spam attempt

twilit cliff
spiral rain
rocky canyon
#

turn the gravity down..

vast vessel
rocky canyon
#

or turn the force up

#

ohh i know what that is ..

rich adder
rocky canyon
#

set ur velocity to 0 right before adding force

twilit cliff
rocky canyon
#

looks fine to me

rich adder
rocky canyon
#

just remake the script w/ a different name

#

if it happens again u def have some compile errors hiding from you..

vast vessel
rocky canyon
#

are there any other classes inside the script?

rich adder
spiral rain
rich adder
rich adder
#

unity just sets z to 0

#

its a 3D engine regardless

modest hollow
#

im curious on how storing information for online games would work, for example a players items

astral falcon
rocky canyon
#

database or external files somewhere

spiral rain
modest hollow
rocky canyon
#

you ever gonna turn that laptop off?

#
  • how good is ur internet speeds?
modest hollow
#

internet speed is descent

rich adder
rocky canyon
#

you can def run a server on ur own machine.. i dont hear many ppl doing it

rich adder
#

because its unsafe af (requires opening ports in your firewall / router)

#

also limited by your ISP bandwidth

rocky canyon
#

theres free DB's out there

modest hollow
rich adder
rocky canyon
#

i use MongoDB

rich adder
#

mongo is good too but its not safe to store connection strings inside a client so something with an SDK is better

#

Realm is good for Unity and interacts with Mongo

rocky canyon
modest hollow
rich adder
#

its pretty much a lesson for later on, start making something singleplayer and learn first

rocky canyon
#

what about Firebase?

modest hollow
#

but ive always wanted to do multi

rocky canyon
#

don't we all

rich adder
#

Non-SQL are fun and quick to work with

#

esp in a gaming environment

modest hollow
#

ive had to learn sql lol

#

its not fun

rocky canyon
rich adder
#

its good to know

modest hollow
#

alr so the advice is to get either a free or paid server

#

online?

rich adder
#

they all have free tiers

modest hollow
#

thats good

rich adder
#

aws has servers too and databases

modest hollow
#

nice, so i presume databases store information that can be accessed by any client in code

rich adder
#

well it gets tricky

#

you wouldnt want to store your DB connections directly in the client code

#

you need to interact with it through an API typically

modest hollow
#

yeah for sure, i would just referance it from the actual database instead of storing stuff no?

rich adder
#

hence why pre-made solutions + SDKs exist like Unity UGS

modest hollow
#

mhm

#

because i wanted to use databases to store large strings that represent world data

#

and players can create worlds and others can visit them by typing in the world name

rich adder
#

You can make multiplayer with just databases if the game is not exactly realtime

modest hollow
#

and the code can just create the world by finding the world data

rich adder
#

think chess

modest hollow
#

for sure

#

but constantly updating player movement would be like

#

unoptimal no?

#

or

rich adder
#

well you better have a server with lots of writes 😛

modest hollow
#

yee lol

astral falcon
#

You want to update as less as possible, thats why your client will try to predict where it might move before the server approves in a fixed update manner.

rich adder
#

but this allows for example, if someone disconnects, the game can easily resume back or you can take "pauses"

#

p2p is not always the way

#

depends what game/project you're making

modest hollow
#

and will display the world that you are currently in

#

by finding the world data

astral falcon
#

Maybe just look into some basic tutorials just to get the idea of how things are done in network for different types of games.

modest hollow
#

and everytime a change is made to the world, for example a player places a block, then the world data would have to be updated

rich adder
rich adder
#

the concepts are exactly the same

modest hollow
#

i have tested it

#

but like

#

with databases

#

offline

#

on my computer lol

#

rather than on servers

rich adder
#

server is just someone else's computer or yours ig

modest hollow
#

yeah

#

wouldnt be that much harder

#

ig

#

you would just have to referance another database

rich adder
#

much more involved is figuring out authnetication and all that

#

securely

modest hollow
#

true

rich adder
#

but yeah luckly unity has built in Auth and built in DB so its all connected

frigid sequoia
#

Kinda of a really abstract question, but... how do I make like arquing proyectiles?

#

Like they track a target but like something like this

frigid sequoia
summer stump
#

Ballistic trajectory

astral falcon
#

Sounds like a bezier math question

frigid sequoia
summer stump
#

But that has mutliple meanings

#

Parabolic arc.
Or ballistic trajectory like I said
Those would be terms to research

rich adder
#

In mathematics, a parabola is a plane curve which is mirror-symmetrical and is approximately U-shaped. It fits several superficially different mathematical descriptions, which can all be proved to define exactly the same curves.
One description of a parabola involves a point (the focus) and a line (the directrix). The focus does not lie on the d...

vast vessel
frigid sequoia
#

I mean I am not looking for a mathematically correct parabola; I was more into like a random thing where it kinda arcs a little before hitting the target

rich adder
#

im just giving you help with what to find

#

its up to you how to apply that to unity

modest dust
frigid sequoia
# rich adder im just giving you help with what to find

Yeah, yeah I got that but I was thinking something more about the lines of... the proyectile does get a bit of upwards momentum before going full tracking, more than an actual formula for an animation between two points, cause the target is gonna be moving, so I think that would make the animation look really choppy

hushed hinge
#

because I am struggling with this one

astral falcon
modest hollow
#

instead of having players make lobbies in multiplayer, can you theoretically just have one lobby that every player thats in the game just automatically joins?

astral falcon
# frigid sequoia Yeah, kinda

I would look into bezier curves then or you just split the animation into uplift and seeking codewise and just alter the timespan depending on the distance for example

astral falcon
modest hollow
#

i cant make lobbies as worlds since i want worlds to exist forever

#

in databases, that store their current state

astral falcon
modest hollow
summer stump
modest hollow
astral falcon
summer stump
modest hollow
#

oh alr

frigid sequoia
astral falcon
vast vessel
#

how do i find out where my code is getting stuck in a inf loop?

#

nvm, this is the last break point that was hit before unity stopped. any idea why im getting a inf loop?

#

here is FireFlechette():

private void FireFlechette()
        {
            int i = Mathf.RoundToInt(Random.Range(0, flechetteEffects.Length));
            Transform muzzle = flechetteEffects[i].transform;

            flechetteFireAudioSource.PlayOneShot(flechetteFireSound);

            Vector3 dir = muzzle.position - (targetingSystem.hasTarget ? targetingSystem.Current_Target.position : transform.forward * 10);
            Hunter_Flechette flechette = flechettePool.Get();

            flechette.Init(dir, muzzle.rotation, muzzle.position, flechettePool, flechetteSpread);
        }
slender nymph
#

what does flechette.Init do and do you do anything on get for the object pool

#

also are you actually certain that this is where your infinite loop is coming from?

vast vessel
#

also fireRate is 0 by accident, maybe that has something to do with it?

#

but then again. the for loop only does 6 iterations

#

flechetteBurstCount is 6

slender nymph
#

well then either the infinite loop does not happen here, or it happens in getting the object from the pool

vast vessel
slender nymph
#

if you cannot break it using the debugger then you'll have to force close the editor

vast vessel
#

alr

#

its definitely happening here. when i comment this out, i no longer get stuck in a loop

slender nymph
#

show how you've set up the object pool since i've pointed out twice now that the issue is likely happening when you get something from the pool

vast vessel
#

also using unitys own pooling namespace btw

#

prefab is assigned

slender nymph
#

show the entire class for the flechette. and for the love of god share the !code correctly. screenshots of code are a pain in the ass

eternal falconBOT
slender nymph
#

yeah you have an infinite loop in Update

summer stump
#

Using a while loop in update is often not right

vast vessel
#

ohhhhhh

#

shit, i wanted to put this in a coroutine.

#

thanks 🙏

#

ig ill just make the while, into a if statement

summer stump
vast vessel
summer stump
queen adder
#
public class CoinScript : MonoBehaviour
{
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Coin")
            Debug.Log("touching");





        


    }


    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
```   when I touch the coin it does not recognize it at all, it is not detecting collision.
ornate lynx
#

{ } of the if statement are mission

queen adder
#

what do you mean

rich adder
slender nymph
#

they are assuming a compile error for some reason despite that being perfectly valid code

ornate lynx
#

well mb

rich adder
#

If(condition)
//I dont need {} for 1 line

slender nymph
#

after you ensure that is working, fix your logic so you are not relying on object names and instead check a tag or for a specific component

ornate lynx
rich adder
ornate lynx
#

alr i see what u mean

#

mb

queen adder
#

yes guys I did the same thing couple hours ago and it worked perfectly, now it wont work with gameobject.name or gamobject.tag

#

I have the same code in the other script attached to player

#

and it recognizes the coin well

rich adder
slender nymph
queen adder
#

nope I dont understand what u mean cuz im completely new

summer stump
queen adder
#

but it worked just few hours ago what is the issue now

rich adder
#

well this is now, so u have to debug it

summer stump
slender nymph
summer stump
#

Maybe not in code

vast vessel
#

hey guys, why is the pool size 1, when its supposed to be 20?

#

pool is initialized in awake

rich adder
#

where is it populated tho?

slender nymph
#

that is the default capacity that the stack used by the pool is created with. it does not automatically populate the pool with that many objects

vast vessel
#

oh... alright.

queen adder
slender nymph
#

make sure that you are using the CompareTag method for checking the tag, not using .tag ==

queen adder
#

my bad I fixed it

rich adder
queen adder
#

i was adding tag to the coin instead of player ❌

summer stump
summer stump
queen adder
#

yeah idk, I made the script work fine and when i came home it doesnt work haha.

rich adder
queen adder
rich adder
#

doesn't hurt to learn how to do it properly for next time

summer stump
sleek orchid
#

Ey lads!

I am trying to do a simple script to make an object to move towards the left side of the screen however there's this error:

NullReferenceException: Object reference not set to an instance of an object
ObstaclesMovement.FixedUpdate () (at Assets/Scripts/ObstaclesMovement.cs:13)

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

public class ObstaclesMovement : MonoBehaviour
{
    private Rigidbody2D rb;
    private float speed = 5f;


    void FixedUpdate()
    {
        rb.velocity = Vector2.left * speed;
    }
}
undone harbor
rich adder
#

assign

sleek orchid
#

I will try

queen adder
#
public class CoinScript : MonoBehaviour
{
    public Rigidbody2D coinMove;
    public float timerCount = 0f;

    void timer()
    {
        if (timerCount < 2)
            timerCount = timerCount + Time.deltaTime;

        if (timerCount >= 2)
            Destroy(gameObject);
    }




    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Player")
            coinMove.velocity = new Vector2(0, 1);

        if (collision.gameObject.tag == "Player")
            timer();

    }
``` I have the function timer which says to destroy gameobject 2s after it has been touched, it is not working.
rich adder
#

skip all this, and just set a time inside Destroy's second parameter

rich adder
#

Destroy(gameObject, 2f)

rare basin
#

you dont need to use Update for it

queen adder
sleek orchid
#

It worked as intended, thanks guys ❤️

queen adder
rare basin
#

just instead of calling timer()

rare basin
#

call the destroy with delay parameter

queen adder
# rich adder show what u wrote
public class CoinScript : MonoBehaviour
{
    public Rigidbody2D coinMove;
    public float timerCount = 0f;

    void timer()
    {
        if (timerCount < 2)
            timerCount = timerCount + Time.deltaTime;

        if (timerCount >= 2)
            Destroy(gameObject, 2f);
rich adder
#

how did i know you would write it like this..

queen adder
#

how didnt you

#

u said skip all this

rich adder
#

if you already made a 2 second timer from destroy , why did you keep the rest of broken "timer"

queen adder
#

idk man Im new

rich adder
#

and just do Destroy(gameObject, 2f); where you need it..

queen adder
#
public Rigidbody2D coinMove;
public float timerCount = 0f;

void timer()
{
    

    if (timerCount >= 2)
        Destroy(gameObject, 2f);
}
``` like this?
rich adder
#

no not at all

#

why is timer still here

#

why is destroy in a float that never increases

queen adder
#

cuz im not u

rich adder
#

like i said already, all the code in timer() isn't needed.

#

just use Destroy with the timer it has, where you need it..

#

if (collision.gameObject.tag == "Player")

terse raven
#

is it better to use a rigid body or a character controller. Also I;ve just tried adding a jump force and for some reason it counteracts all other forces and stops moving horizotnal.

elder locust
#

Hello, I have a little issue blocking me on my way to realize a QTE, it's the last step I'm struggling one :
I want to be able to use the new input system into an "OnTriggerEnter2D" method, though, it's not working...

Here is the code of everything I declared (for example variables)

public GameObject objectToRotate;
public GameObject pivotPoint;
public int rotationSpeed;
public GameObject[] zoneQTE;
public int currentZoneQTE;

public PIA playerInputActions;

private void Awake()
{
    for (int i = 0; i < zoneQTE.Length; i++)
    {
        zoneQTE[i].gameObject.SetActive(false);
    }

    currentZoneQTE = Random.Range(0, zoneQTE.Length);
    zoneQTE[currentZoneQTE].gameObject.SetActive(true);

    playerInputActions = new PIA();
    playerInputActions.PlayerInput.Enable();
}

Here is the code of the method

private void OnTriggerEnter2D(Collider2D collision)
{
    if (playerInputActions.PlayerInput.QTE.triggered)
    {
        Debug.Log("Hello world.");
    }

    if (collision.gameObject.tag == "zone-qte")
    {
        if (playerInputActions.PlayerInput.QTE.triggered)
        {
            Debug.Log("Hey, QTE has been succesfully done !");
            zoneQTE[currentZoneQTE].gameObject.SetActive(false);
            currentZoneQTE = Random.Range(0, zoneQTE.Length);
            zoneQTE[currentZoneQTE].gameObject.SetActive(true);
        }
    }
}```

I've tried many things and the new input system is working I'm calling an input into the update() method, it's really calling an input from the OnTriggerEnter2D which is creating issue...
#

Don't hesitate to @ me ! :>

devout flower
#

I dunno what a QTE is, but since this involves an input, are you sure you wanna do it in OnTriggerEnter?

#

That means it'll only check when you initially enter the collider

elder locust
#

QTE stand for QuickTimeEvent, it's those little interaction you can have on screen when doing some actions !

devout flower
#

OnTriggerStay, i guess

elder locust
#

In my case, I want to do kind of Dead By Daylight like QTE ! If you ever played the game ? ^^

elder locust
elder locust
#

What is this ? It's like onTriggerEnter but all the time where it's triggered ???

#

I didn't knew !

#

I'ma try that !

devout flower
#

OnTriggerStay is when it's in the collider

#

Okey doke

snow girder
#

hey guys how do i make it so that buttons aren't clickable only selectable by arrow keys

elder locust
# devout flower No :/

To make it quick, in dbd when you repair generators for example, there is a circle popping on the screen with a cursor rotating around it ! when the cursor's hovering a certain zone of the circle, you gotta press your keybind ! ^^

devout flower
#

Ooooo ok

#

Yeah i think you need OnTriggerStay, to constantly check while it's in the zone

sleek orchid
rich adder
#

post code properly

sleek orchid
#

oh, yeah...

devout flower
#

@elder locust i'm curious, did it work?

sleek orchid
# rich adder post code properly
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ObstacleSpawner : MonoBehaviour
{
    private float time = 0f;
    private float spawnDeltaTime = 1.5f;
    public GameObject obstacle;
    [SerializeField] float height = 1f;
    [SerializeField] float offset = 5f;

    void Start(){
        obstacle = GameObject.Find("Obstacle");
    }

    void Update(){
        if(time > spawnDeltaTime){
            GameObject go = Instantiate(obstacle);
            go.transform.position = new Vector2(offset, Random.Range(height, -height))
            time = 0;
            Destroy(go, 10);
        }
        time += Time.deltaTime;
    }

}
#

Sorry.

elder locust
sleek orchid
#

found it

#

kekw

vale geode
#

hi im experiacing a syntax error and i cant identify it, its on line 34 from what console says

ivory bobcat
#

Maybe show the error from the console

sweet wasp
vale geode
rich adder
#

yes this is wrongly defined method

ivory bobcat
#

You'd require both for the function signature

sweet wasp
# vale geode folder

it looks like you are making a param of type Grunt_gun and not giving it a name

rich adder
#

@vale geode need to configure their IDE

grizzled zealot
#

I created an svg (300x300 pixels), added the com.unity.vectorgraphics package, and dragged the svg to a game object. It gets displayed but does not fill a 300x300 gameobject.

#

What's a 300x300 gameobject in pixels? is the value of height 100 equivalent to 100 pixels?

vale geode
#

thank for your hellp everyone

rich adder
vale geode
summer stump
eternal falconBOT
rich adder
summer stump
#

And it is just way easier to code when it is configured

modest hollow
rich adder
modest hollow
summer stump
#

Strictly meaning ONLY one. Nav uses multiple

rich adder
#

also strange to send that on that reply to someone else

summer stump
burnt vapor
#

Databases? I just ask the user to remember the state and have them fill in a form before each game

rich adder
#

lol

#

ah good ol days of passcodes

burnt vapor
#

Why change when the initial solution worked fine

frigid sequoia
#

Guys I got this from chat GPT asking for a editor tool that assigns prefabs in a folder to a list, but I and like veeeey confused with the part that treats the folder as a GameObject, is that a thing?

teal viper
north kiln
#

Don't ask a text generator to generate meaningful text

#

it doesn't know anything, and there are multiple nonsensical things it's written

#

and I'm not going to fix them, because it's against our conduct to begin with

slender nymph
#

This is exactly what I'd expect from gpt lol. It saw "prefab" and probably took a hint from the hundreds of bad tutorials that all use GameObject variables with prefab in the identifier and just ran with it

north kiln
#

#📖┃code-of-conduct

- • Posting unverified AI-generated responses or failing to mark AI-generated content as such.
frigid sequoia
#

Is that wrong?

north kiln
#

It's unverified because it doesn't work

#

We're not here to correct the mistakes of autocomplete

#

If you haven't verified that it works, then it's not allowed here

wooden vine
#

Hi, I have used a unity asset which automatically disables the cursor once I click start. Is there any script I can use to bring it back?

frigid sequoia
wooden vine
#

And also, when I load a new scene from another scene, my materials for my object disabled. However, in the actual scene, it is still there. Is there any solution?

north kiln
frigid sequoia
#

Ok, well scrapt that how do I do this from scratch then? How can I get reference to an entire folder and its children?

wintry quarry
#

they're just assets

wooden vine
wintry quarry
#

what is it supposed to show

summer stump
wooden vine
real falcon
#

I have a question about DeltaTime

#

so I'm moving the character controller with this:

#

controller.Move(playerVelocity * Time.deltaTime);

#

but then in another part of the code im doing this

#
        
        // Friction
      ...

        
        playerVelocity += fric * 0.01f;```
#

do I need to multiply these too, even though im already multipliying when I move the controller?

strong moth
#

how do i declare a ref int pre c# 11.0

wintry quarry
rocky canyon
rocky canyon
#

and praets right.. it depends on where ur +='ing

wintry quarry
wintry quarry
wooden vine
#

the spaceship is black when I load into the next scene

rocky canyon
#

wheres the lights?

wooden vine
real falcon
#

im not sure, I'm just trying to add it. basically I have playerVelocity, and this is moved by the players inputted direction and then by friction, which is a vector that is opposite to it and some fraction of its magnitude

#

I'm not specifically trying to add it per second or per frame, I wouldnt know the difference

rocky canyon
rocky canyon
real falcon
#

ah it's all in update yes

#

I dont use FixedUpdate for the player movement

rocky canyon
#

no need its a CC.

#

so u probably want to use deltaTime on ur += lines too.. since they run in update im about 73% sure.. and then you can modify the values to take in consideration the new multiplier

real falcon
#

hmm ok

#

honestly I wonder if that factor I have is just to account for the fact that it's not there

#

I propably realized it felt way too high

#

im HOPING that a lack of deltatime is why the movement feels very slightly but subtly off in weird inconsistent ways

wooden vine
rocky canyon
#

it'll get higher once u multiply deltaTIme

wooden vine
#

I wasn't able to find it

real falcon
#

im thinking when I spin around too fast it drops the frames and this causes an issue

rocky canyon
#

why would u have lights in the scene if u run it stand-a-lone.. but when u load into it they dont..

#

🤔 thats the question

wooden vine
rocky canyon
wooden vine
#

Thank you

rocky canyon
#

👍 no problem

wooden vine
#

But another problem is that when I load in to the next screen, my cursor is hidden. What is the simplest way to unhide it

rocky canyon
#

put a script in that scene that unhides it in Awake()

frigid sequoia
#

Cause I cannot find that

north kiln
#

Use the overload that has the options to do that

carmine sierra
#

Right now in my game, I have a placement system which places exactly at the mouse position, but as this requires really steady hands, I want the placement to be more grid locked, how could I go about doing this? My current script instantiates an object in the exact mouse-world position. Thanks

wintry quarry
carmine sierra
#

is it complicated to implement

wintry quarry
#

It has methods that will let you easily convert a world space position to a grid position

#

no

carmine sierra
#

thanks ill check it

wintry quarry
# carmine sierra thanks ill check it

As an example, using a grid, you would do this to get a locked grid position for a given mouse position:

Vector3 mouseWorldPos = whatever;
Vector3Int gridCoords = myGrid.WorldToCell(mouseWorldPos);
Vector3 roundedPos = myGrid.CellToWorld(gridCoords);
// OR
Vector3 roundedPos = myGrid.GetCellCenterWorld(gridCoords);```
#

depending if you want the grid centers or the grid corners

carmine sierra
#

yeah seems easy

wintry quarry
#

The nice thing is you can set the grid up exactly as you want from the editor, including cell size, cell shape, scale, position, rotation, etc.

#

and you don't have to worry about that stuff in code

carmine sierra
#

I have one function which gets the mouses position, this is used in about four scripts. Is it better to make a separate script which just constantly executes that function and the function is accessed from that one script?

#

Rather than executing it upto three times simultaneously from each script

frigid sequoia
#

How the hell is this returning out of range exception?

wintry quarry
rocky canyon
#

also .Count is the total number of elements.. so if u have 3 elements.. it returns 3.. but there is not a 3rd index.. theres only 0,2,1 so u need to - 1 to get the last index

wintry quarry
#

-1 is not needed

#

Random.Range is exclusive of the top end for the integer version

rocky canyon
#

oh shit yea u right..

rocky canyon
frigid sequoia
wintry quarry
rocky canyon
# wintry quarry no

lol, anytime im wrong or get called out i write it down on a post-it and stick it to my wall

frigid sequoia
#

Ok, that shouldn't be a problem as I add more stuff and confirms that my tag to make some items only spawn once does work

#

So it is actually good sign XD

summer stump
#

Handle errors gracefully when possible

wooden vine
wintry quarry
#

defensive programming would indicate you should do something like:

if (pool.Count == 0) {
  throw new Exception("The loot pool is empty!");
}```
#

or handle it in some other way

rocky canyon
frigid sequoia
#

Tell it to roll for a different item?

wintry quarry
summer stump
#

"Should never" is something you should never say or think as a software engineer

rocky canyon
#

edge-cases wants to know ur location 😄

wintry quarry
#

Beware of creating other problems though - like an infinite loop

swift crag
#

I have code that absolutely expects it to never return 1f

wintry quarry
swift crag
#

well, it does at least bail out with some kind of vaguely acceptable result

swift crag
#

Also wrong sound effect

rocky canyon
#

throw new Exception("The loot pool is empty!");
does this show a debug log? and/or stop the game?

#

i have a spare project open.. imma just test it 👍 need to figure it out anyway..

wintry quarry
swift crag
#

I've thought a few times about being able to do that

rocky canyon
#

ahh, so it throws an error but doesnt stop the gameplay.. nifty

#

lol.. i should handle more errors too.. (but i dont expect any errors) 😅

wintry quarry
carmine sierra
#

if im calling a function from another script, how do I call a variable that the function returns

rocky canyon
#

actually the issue is.. i dont know when a situation would cause an error that i would need to be weary of..

frigid sequoia
#

Not quite sure if this could create a endless loop, seems like it?

wintry quarry
wintry quarry
#

If not, then no it can't cause infinite recursion

carmine sierra
frigid sequoia
rocky canyon
#

you could use MyFunctionThatReturnsAFloat() anywhere that a float is expected

wintry quarry
frigid sequoia
#

Though this could still return out of range exception, just even more unlikely

rocky canyon
#

Random.Range(0,MyFunctionThatReturnsAFloat());

#

for ex.

wintry quarry
frigid sequoia
#

How could I tell it to keep trying though?

wintry quarry
#

maybe you should have it only select loot pools that have at least one item in them?

carmine sierra
#

I want to access the mouse position from this script in other scripts. if i want to access the always changing mouse position, would i call it in the update function of the other scripts which call this function?

frigid sequoia
rocky canyon
# frigid sequoia How could I tell it to keep trying though?

ive never found a good solution for this..
ive had the same issue when trying to find a random number.. say the number doesn't work? do i try to run it again?
and what if i do run it again.. and the 2nd number doesn't work.. do i run it a 3rd time? lol

wintry quarry
wintry quarry
#

get rid of the Update

#

and get rid of the field

carmine sierra
#

which field

#

so id call it in the update function of the other scripts accessing the function?

wintry quarry
# carmine sierra which field
public static class MouseHelper {
  public static Vector3 GetMousePos() {
    Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
    mouseWorldPos.z = 0;
    return mouseWorldPos;
  }
}```
#

basically

#

doesn't need to be a component at all

#

doesn't need any fields

#

or storage

#

just call the function

carmine sierra
#

bruh ive never seen that

frigid sequoia
rocky canyon
wintry quarry
carmine sierra
#

like this?

swift crag
wintry quarry
#

Yes then in another script you just do MouseHelper.GetMousePos()

carmine sierra
#

do i need to drag anything to reference it?

rocky canyon
#

nope

carmine sierra
#

where do i store the script

#

in an empty gameobject?

rocky canyon
#

nope

swift crag
carmine sierra
#

interesting

rocky canyon
#

it just works.. as long as its in ur project folder

swift crag
#

only components are attached to game objects

carmine sierra
#

does it need to be in the hiearchy?#

rocky canyon
#

nope

swift crag
#

and only classes that derive from UnityEngine.Object even matter in unity's eyes

#

you can do whatever your heart desires with a class that doesn't derive from UnityEngine.Object

carmine sierra
#

whats that kind of script called (need it for my documentation)

rocky canyon
#

Static

swift crag
#

You may call it a "plain old C# object" (but this class is fully static)

carmine sierra
#

static script?

swift crag
#

so...plain old C# class, at best?

rocky canyon
#

POCO

swift crag
carmine sierra
#

plain old is the actual name?

swift crag
#

that's it

#

it's a class

carmine sierra
#

oh okay

#

and then is getmousepos the method

swift crag
wooden vine
carmine sierra
#

fr

swift crag
#

the rules that apply to MonoBehaviour (a kind of component) are not universal

#

Unity just has some special rules for its own kinds of classes

rocky canyon
#

if u mention Poco, advanced programmers will know what u mean but yea, its just a class that doesn't derive from Monobehaviour so it doesn't need to be on a GameObject

carmine sierra
#

i just ignore everything above my variable initialisations

#

yeah ill put poco in brackets

rocky canyon
rocky canyon
#

Cursor.lockState = CursorLockMode.None;

#

no in the awake of that new script on ur new scene

#

its locked b/c ur Controller from the previous scene locks it

#

just like it hides it

wooden vine
#

Yea

#

so do i still need this: Cursor.visible = true;

rocky canyon
#

so.. just add that line to the awke and it will be visible and unlocked

#

when the scene loads

carmine sierra
#

sorry how do i call it?

rocky canyon
#
        Cursor.visible = true;```
wooden vine
#

Oh, Thank you

swift crag
carmine sierra
#

woops your rigfht

swift crag
brave compass
carmine sierra
#

and if i want to call the returned mouseworldPos variable?

rocky canyon
#

and you dont call it per say.. u just access it when u need to assign it..
Vector3 mousePos = MouseHelper.GetMousePos();

carmine sierra
#

but the returned variable

#

mouseWorldPos

rocky canyon
#

yes, thats what its returning

wooden vine
carmine sierra
rocky canyon
#

MouseHelper.GetMousePos();

carmine sierra
#

ohh okay

#

so before I had mouseWorldPos where this is

#

and it is the same?

rocky canyon
#

if you debug Debug.Log(MouseHelper.GetMousePos()); it will show u a Vector3

carmine sierra
#

I do need it to be called in an update function though, so could I do that in the static class or in the scripts

#

if that terminology is even right

wintry quarry
#

put it in a variable, as mentioned earlier

wintry quarry
carmine sierra
#

yeah i get that thanks

#

but i need the fucntion to be in an update function

#

so would i edit that in the class

carmine sierra
#

and how? Cause im unfamiliar with doing this static class thing

carmine sierra
wintry quarry
#
void Update() {
  Vector3 mousePos = MouseHelper.GetMousePos();
  // do whatever
}```
wintry quarry
carmine sierra
#

how comes?

wintry quarry
#

you just call the function when you want the current mouse pos

carmine sierra
#

okay ill try that

#

'MousePos' is missing the class attribute 'ExtensionOfNativeClass'!
anyone know what this means

wintry quarry
#

remove it

carmine sierra
#

alr

wintry quarry
#

because it's not a monobehaviour anymore

#

and doesn't need to be

lusty mango
#

Could any of you guys help me with an issue I'm having with my layout? I have a prefab that has child GameObjects TMP Text, and Buttons. They're the child of my content GameObject, and I just cannot get this thing to set each prefab's size according to the text component. I can send more pictures if needed

carmine sierra
#

woah its working

scarlet skiff
carmine sierra
#

as im using c# to code my game, are the functions im making functions or methods?

slender nymph
iron hull
carmine sierra
#

is every variable called an attribute then?

carmine sierra
slender nymph
#

no, attributes are something different in c#

#

pretty sure only java calls class-level variables attributes

rich adder
#

glad microsoft doesnt :p

iron hull
#

I'm using an animation to upscale my gameobject from zero, but this causes it to get stuck into other objects sometimes hmjj
Is there a way to make it redo its collisions or should i use some janky fix like spawning a fullsize game object after its animation is complete? Confused

rich adder
#

are those rigidbodies?

iron hull
#

Yeah

rich adder
#

normally they should push each other out no?

#

are you reizing collider too?

iron hull
rich adder
#

I actually never tried scaling , maybe try calling Physics.SyncTransforms

twilit cliff
iron hull
#

I'll give it a go, thanks! just set up a coroutine to run with it when collision happens after a few seconds hmjj will see if it gets fixed Prayge

rich adder
iron hull
#

seems to work, stuff gets pushed out peepoAwesome

rocky canyon
#

id start with that error.. assuming you want to get a random number for your~~ _creatures GameObject[] ~~ (should be a List<> if you're using .Count) you could replace list.Count with _creatures.Count that would store a random number that falls within the bounds of ur array

#

then you could enable that creature

#

it appears that each creature disables itself on click.. and calls the gameManager's CreatureClick() function to enable the next one

wintry quarry
#

do you have a specific question here? You have a compile error in your code, you should probably fix that.
After that, think through what you want the script to do step by step, then get to work writing it.

rich adder
#

arrays don't have a property called Count

rocky canyon
#

Is there anyway to have the Custom Debug open the SandboxControl script.. such as the Unity one does.. could I pass in context to the custom static debug?

rocky canyon
#

I can pass in context to highlight the gameobject but it still opens the static class

rocky canyon
#

ohh neat, this is exactly what im hunting for

#

double click still opens the static script.. but atleast now the actual script and line number is visible in the log w/o scrolling so I can just click it instead

ebon robin
#

How do we make a State Machine with a generic State like
public class StateMachine<T> : MonoBehavior where T : State
and also make StateMachine known to the state like declare its statemachine owner?

verbal dome
#

I think you would need to use an interface here

eternal needle
verbal dome
#

Nothing here makes State inherit from StateMachine though 🤔

eternal needle
#

At least to me, I dont see the use of generic here

verbal dome
#

I was thinking more likecs public class StateName : IState<StateMachineName> If they want the state to know about the machine

#

But it's not necessary

slender nymph
#

why would the state need to know about the state machine though? that relationship should really only go one way

hoary ice
#

i wonder that i always find a hard time implementing something with delay

private void CheckAndUpdateGoblinEmployment()
    {
        // Ensure GoblinCollection reference is set
        if (goblinCollection != null)
        {
            // Get all child game objects of the GoblinCollection
            foreach (Transform child in goblinCollection.transform)
            {
                // Get the Goblin component attached to the child game object
                Goblin goblin = child.GetComponent<Goblin>();

                // Check if the Goblin component exists and the child game object is inactive
                if (goblin != null && !child.gameObject.activeSelf)
                {
                    // Set the isEmployed variable to true
                    goblin.isEmployed = true;

                    // Start a coroutine to activate the game object after a delay
                    StartCoroutine(ActivateGameObjectDelayed(child.gameObject));
                }
            }
        }
        else
        {
            Debug.LogWarning("GoblinCollection reference is not set in GameManager.");
        }
    }

    private IEnumerator ActivateGameObjectDelayed(GameObject gameObject)
    {
        // Wait for 2 seconds
        yield return new WaitForSeconds(2f);

        // Set the game object to active
        gameObject.SetActive(true);
    }

if the gameobject is set to active false set variable isEmployed to true then set active to true after 2 seconds delay

ebon robin
#

maybe i should just do that in statemachine

static bay
#

I dont think that's good design.

#

Personally I don't think states should know how or when they transition.

ebon robin
#

i dont really want to make a dictionary for possible transitions for each states

static bay
#

Why not?

ebon robin
#

my new code have pre-initialized components, constants and only resets variables on enter. the states transition by a bunch of ifs

#

in controller of course

static bay
# ebon robin my new code have pre-initialized components, constants and only resets variables...

The way I would do it is have the StateMachine hold a Dictionary<State, List<Transition>>.

The StateMachine can have a method...
public void AddTransition(State from, State to, Func<bool> condition)
In the function create a new Transition which holds all these variables.

When you are building your state logic, create all your states, set up your transitions, toss the state machine an initial state, and then it just goes.

#

Separating the logic of a state from the transition allows you to rewire it much more easily.

#

Otherwise adding new transitions requires you to constantly toss references between states.