#💻┃code-beginner

1 messages · Page 65 of 1

rich adder
#

although it might just be covering a bigger problem

#

thats how these things go

#

why is it trying to rotate towards 0 in the first place n all that

pliant raptor
eternal needle
eternal needle
open vine
#

Hey can anyone explain what im doing wrong with polymorphism? So I have a ScriptableObject Item, and I have Consumable inherit from Item. In my Item script i made it an abstract class with the abstract method OnUse(). In my Consumable script I have a field for a Consumable script, and have an override OnUse() method where I call the consumable reference OnUse() . Then I made a Medkit script that inherits from Consumable and overrides the OnUse() function but for functionality I want the Medkit script to inherit from Monobehavior but I know Unity doesn't support multi-inheritance. I'm sure I'm not doing it correctly what should I change and why?

wintry quarry
#

Can I ask why Item is a ScriptableObject in the first place?

#

Also you may want to consider that there's two pieces to this:

  • There's the item description which is a scriptable object that contains some static data.
  • There's the in-game representation of the item, which may be a MonoBehaviour.
#

if you have both of those you'll need to split those up

#

There may even be more representations of the item in your game too - for example displaying the item in the inventory vs on the ground in the world

open vine
# wintry quarry Can I ask why `Item` is a ScriptableObject in the first place?

So the reason why I want it to be a scriptable object is so that I can create an asset for different consumables that all share common properties. And my thought process for having a consumable field in the consumable script is because all the scripts I planned to add for the consumables were supposed to inherit from the consumable script.

buoyant knot
#

but then it cannot be a monobehaviour

wintry quarry
buoyant knot
#

Monobehaviours get instantiated during runtime

wintry quarry
vague furnace
#

I have problem where my player goes through walls even though the walls have colliders

buoyant knot
languid spire
open vine
wintry quarry
buoyant knot
#

assume you only have 1 instance of an SO for a kind of item

wintry quarry
#

Inheritance is not necessarily the right move here

buoyant knot
#

if you have Consumable : SO, then in pokemon, I would expect a single Potion.asset, HighPotion.asset, and MaxPotion.asset in the entire project

wintry quarry
#

I often end up with a system like:

public class Item : ScriptableObject{
  public List<Effect> effects;
}``` and then make Effect configurable in the inspector in a pretty flexible way
vague furnace
buoyant knot
#

then I would have Item as a POCO, with a field for Consumable for the one consumable it corresponds to.
And Inventory : MonoBehaviour which might have like a List<Item>.

#

the list might have multiple items that each reference a common SO

#

like 4 different entries in the list where the Item’s Consumable field is Potion.asset

open vine
wintry quarry
# vague furnace

Your player's Rigidbody is kinematic. Kinematic bodies do not respond to collisions, obstacles, or forces

#

It's also unclear how you're moving the player in your code.

vague furnace
#

i changed it to dynamic and i can show you the code

buoyant knot
wintry quarry
vague furnace
wintry quarry
# vague furnace

this doesn't show us anything. You're just modifying some variables here, not moving anything.

buoyant knot
#

so I can define Consumable : SO, and then right click to make 10 new .asset files, which are all tied to the definition of Consumable

wintry quarry
eternal falconBOT
wintry quarry
#

share the full script

vague furnace
wintry quarry
#

this will ignore physics entirely

#

you need to move via the Rigidbody if you want physics to work

buoyant knot
#

for pokemon, I would make Item : SO, and HealingItem : Item

vague furnace
#

oh okay thank you ill try that

buoyant knot
#

so all the potions etc could have a specific field for healing value, and you wouldn’t need to have that field for an XAccuracy or so

#

but all items need to be managed by the inventory system

wintry quarry
# vague furnace oh okay thank you ill try that
Rigidbody2D rb;

void Awake() {
    rb = GetComponent<Rigidbody2D>();
}

void Update() {
    Vector2 input = new(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    rb.velocity = input * 5;
}```
#

for example^

vague furnace
#

yea im trying to make borders

wintry quarry
#

aka invisible walls

vague furnace
#

so that the player cant pass trough them

wintry quarry
#

yes those are called colliders

open vine
buoyant knot
#

because the SO doesn’t do anything. It’s a monobehaviour that does

#

Shop : Monobehaviour works with all sorts of items, to modify Inventory (POCO or Monobehaviour)

#

BattleItemMenu : MonoBehaviour looks at items in Inventory, and lets you call the generic Item.UseItem or something

vague furnace
buoyant knot
#

UseItem might downcast to HealingItem, and then call Heal(pokemon, HealingItem)

#

but the SO does not carry code

wintry quarry
#

There's actually nothing wrong with having code on a ScriptableObject

buoyant knot
#

i mean the SO doesn’t have code specific to one .asset

wintry quarry
#

You just have to call it yourself from somewhere

#

Right so - I'm really against the idea of ScriptableObject inheritance for the most part. It becomes completely unweidly to actually create the instances that way

buoyant knot
#

the HealingItem doesn’t have a special function that checks Potion vs HighPotion to call different logic

buoyant knot
queen adder
#

apologies if this is the wrong category, how do i make the player go straight and not up?

buoyant knot
#

inheritance in general is not great unless you put a lot of thought into it

#

SOs are no different

wintry quarry
buoyant knot
#

probably require even more thought tbh

#

btw I do have a different method, with an addon called TypeReferences, where I can tie a type to an SO, and the type can have code.

toxic void
#

Can someone explain to me how exactly angularVelocity is defined with a vector 3? if I use (0,1,0) does it mean the object will rotate 1 degree on the Z axis every time it is called?

queen adder
wintry quarry
#

also "forwards" may mean different things depending on your game style/camera angle, etc.

wintry quarry
buoyant knot
#

So I have BuildingObjectBase, which might correspond to a ground tile, or a goomba, or ? block. Then I can give it a reference to the type GoombaBehaviour. This is a lighter version of using a Prefab, so you want to evaluate that option first.

wintry quarry
buoyant knot
#

does all of this make sense?

#

first make a simple SO. Don’t fuck with inheritance until you have everything under control

#

remember you can only inherit once

#

but you can compose or implement many times

tiny bloom
open vine
summer stump
open vine
#

Then I made HealingItem which Inherits from that ItemData and it contains the public field healingAmount. and the method public Heal()

buoyant knot
#

Inventory should be a POCO because it is just a data structure to allow monobehaviours to edit and query inventory,

#

Inventory’s job is simple: Hold a bunch of items, and let us know what we have, how many etc

#

for that, you probably also want an Item (POCO)

#

the Item should mostly carry ItemData, plus any information that is volatile/transient/temporary. Like current quantity

#

or Favorite

#

Inventory should be able to take simple requests like: AddItem, CountItem, RemoveItem

#

And later FilterItems (to get all items satisfying a given criteria), but you can worry about that later

#

understand?

#

and do you understand why I’m setting it up like this?

vague furnace
#

i have one question i have score system in my game and i want the same score to be displayed in my gameover scene

#

so i know it has something to do with playerprefs but i dont know how to do it

amber dome
#

What do you recommend for a beginner to learn physics at Unity?

buoyant knot
vague furnace
#

what is JSON

buoyant knot
#

look it up. and look up JSON utility

buoyant knot
#

every game uses basic physics. but if you are super new, you might want to start with Godot, as it grows

open vine
# buoyant knot and do you understand why I’m setting it up like this?

Okay yeah, I created the inventory to do what you said, It's a POCO which the methods to add remove count, and initialize the inventory in the start method. Although tbh I'm not too sure the reasons for POCO's aside from performance benefits and that it means it has no dependencies so it can easily be reused for other projects. I created an Item POCO with the field for ItemData : SO. It has a private field for amountOfItem.

amber dome
buoyant knot
#

if something has no reason to be a monobehaviour, it should not be a monobehaviour

#

there are a lot of tutorials on the topic tbh. there’s just a ton

#

it’s such a big topic

#

the point of a monobehaviour is to attach it to a GameObject, and allow it to respond to messages, like Start, Update, OnEnable,…

amber dome
#

curves are usually made with lerp?

buoyant knot
#

try slerp

buoyant knot
#

also we will eventually want to Serialize it to save

#

but even without that point, it still should not be a monobehaviour

open vine
amber dome
#

I'm not sure how cooldowns are done in Unity

wintry quarry
#

with a timer of some kind

buoyant knot
#

you can use a Coroutine

wintry quarry
#

this can be anything from a float variable to a yield instruction in a coroutine

amber dome
#

IEnumerator, right?

buoyant knot
#

yes. and you need to StartCoroutine on a MonoBehaviour

open vine
#

So now that I have these. How would I add the heal functionality to the HealItem which inherits from the ItemData : SO? Would I just make it a method public Heal() in the HealingItem script?

buoyant knot
#

no

wintry quarry
buoyant knot
#

actually, you could add Heal as a public method to HealingItem, which operates on a target

#

then different Monobehaviours can call this method at runtime

#

but be mindful to not edit the SO

#

editting the contents of the SO is bad

#

I might even make it public static Heal

#

does this make sense?

#

i cannot stress enough that you do not want the asset to change during runtime

open vine
#

Okay so I understand that I shouldn

buoyant knot
#

if exactly how Heal works is the same across the whole game, and doesn’t require a lot of specific logic, you should make it a static member of the HealingItem class

open vine
#

t be messing the scriptableobject at runtime. But the reason why I dont understand this is because the way I've been doing my Heal functions is by refrencing the PlayerHealth script and running the Heal function using the argument for the amount. And as you know GetComponent is only available in Monobehaviours so I wouldnt be able to put that function on HealingItem which inherits from ItemData : SO. Btw im sorry for the trouble I dont know why I can't wrap my head around this

buoyant jackal
#

Hi everyone. I am a beginner at Visual Scripting, so this question is probably easy, but I can't find information online. I have received the task of creating a simple movement and power-up system in Visual Scripting. The large script makes my character jump; the other one is my trying to make a power-up to make my character jump extra high after it touches the power-up object. It does not need a set time; it just needs to jump higher after it feels the power-up every time you press the space key to jump. Can anyone help me, please? 🥺

buoyant jackal
#

And thanks 🙂

rich adder
#

no worries! & ur welcome 🙂

queen adder
#

I just understood.. i fixed my issue after all these hours

#

i just had to write "_input.attack = false;" instead of changing the boolean, because the input.attack was true and it was constantly keeping the bool to true

rich adder
#

what was issue?

queen adder
#

and everytime i would put the boolean to false, it would instantly become true again

rich adder
#

ohwait nvm you replied to that XD

buoyant knot
#

GetComponent is a method in gameobjects or components

wintry quarry
buoyant knot
#

if you have a reference to a component or GameObject, just call .GetComponent lol

open vine
#

Oh boy I forgot you could pass references as parameters, no wonder it never worked I just assumed GetComponent was a part of monobehavior. Thanks guys!

buoyant knot
#

i would make Heal just take a reference to the Health component or whatever

#

or rather, it’s smarter to make a generic Status component, to hold any type of status for an entity. Including but not limited to health

ruby python
#

!code

eternal falconBOT
ruby python
#

@wintry quarry Well, this was a lot easier than I thought it would be, all this practice recently is paying off. Thank you for the idea. 🙂

    public void AdjustScore(int scoreReceived)
    {
        playerScore += scoreReceived;
        playerTextScore = playerScore.ToString();

        for (int i = 0; i < playerTextScore.Length; i++)
        {
            MeshFilter meshFilter = scoreDigits[i].GetComponent<MeshFilter>();
            MeshRenderer meshRenderer = scoreDigits[i].GetComponent<MeshRenderer>();
            string digitValue = playerTextScore[i].ToString();
            int indexValue = int.Parse(digitValue);
            meshFilter.mesh = scoreMeshes[indexValue];
            meshRenderer.material = scoreMaterial;
        }
    }
ruby python
#

Fun fun fun 🙂

languid spire
#
string digitValue = playerTextScore[i].ToString();
            int indexValue = int.Parse(digitValue);
            meshFilter.mesh = scoreMeshes[indexValue];

Why?

ruby python
#

It works. lol.

buoyant knot
#

converting an int to a string, then back to an int is good luck

languid spire
#

So does

meshFilter.mesh = scoreMeshes[playerTextScore[i]];
buoyant knot
#

you forgot to increment and decrement it

ruby python
buoyant knot
languid spire
buoyant knot
#

silly would be using division

ruby python
#

Honestly, can't tell if you're being seriously helpful or taking the piss.

buoyant knot
#

taking a piss

languid spire
#

He's taking the piss, I'm being helpful

ruby python
#

Yeah I know you always are. 🙂

slender nymph
languid spire
#

playerTextScore is an array of ints

slender nymph
#

playerTextScore = playerScore.ToString();

languid spire
#

string digitValue = playerTextScore[i].ToString();

slender nymph
#

that's indexing a string to get a char then converting that to a string

languid spire
#

indeed. So

meshFilter.mesh = scoreMeshes[((int)playerTextScore[i])-48];
ruby python
#

Is one better performance wise than the other or is the difference negligable? (genuinely asking. lol.)

languid spire
#

he wants the char representation as an int, my bad

slender nymph
#

you may want to subtract '0' from that unless the values are supposed to be like 48 off

ruby python
#

Hmm? Not sure what you mean. I was getting weird high numbers earlier while I was figuring it out, but now the scores are representing correctly etc.

slender nymph
#

steve is implying that you can just cast the char to an int instead of parsing it like you're doing. but '0' == 48 whereas int.parse('0') == 0

ruby python
#

Ah I see. Well tbh, this works, so I'm happy with it. lol.

#

But honestly thank you for the input. It is very much appreciated. 🙂

slender nymph
#

honestly though you're creating a bunch of garbage unnecessarily. when you can just use the actual score value before converting it to a string and get the individual digits from that fairly easily

sour hound
#

i have a bug where my code randomly stops working and forces me to restart the editor

#

works fine normally but sometimes it just randomly stops working

slender nymph
#

infinite loop

sour hound
#

wouldnt the code always fail when i press play every time in that case?

slender nymph
#

no, unless unity has somehow solved the halting problem

#

an infinite loop will cause the editor to freeze because it is stuck in the loop and cannot proceed to the next frame

sour hound
#

no the editor doesnt freeze

slender nymph
#

then what do you mean by "my code randomly stops working and forces me to restart the editor"

sour hound
#

sometimes the script just wont run when i press play, but most of the time it runs

#

then the script wont run when i press play again

#

however when i restart the editor the script works fine for a while

slender nymph
#

and by "won't run" you mean . . .?

sour hound
#

until it randomly stops running after a while

#

its a gun script, i cant shoot and it wont show me anything in the debug.log

#

it normally does

#

restarting the editor solves the issue temoporarily

slender nymph
#

oh you know what, i see you subscribing to some static events but not unsubscribing them. have you turned off domain reload without understanding what that does?

sour hound
#

do you have to unsubscribe to them?

slender nymph
#

yes

rich adder
#

yea

sour hound
#

does the script fail after a while otherwise?

slender nymph
#

especially if you have turned off domain reload because then you're not cleaning up your static event so it will keep the same subscriptions even after restarting play mode. so you'll end up with some null reference exceptions and the like preventing the newer subscribers from reacting to the events

ruby python
#

!code

eternal falconBOT
ruby python
#
public void AdjustScore(int scoreReceived)
    {
        playerScore += scoreReceived;
        playerTextScore = playerScore.ToString();

        for (int i = 0; i < playerTextScore.Length; i++)
        {
            MeshFilter meshFilter = scoreDigits[i].GetComponent<MeshFilter>();
            MeshRenderer meshRenderer = scoreDigits[i].GetComponent<MeshRenderer>();
            meshRenderer.material = scoreMaterial;
            meshFilter.mesh = scoreMeshes[((int)playerTextScore[i]) - 48];
        }
    }
#

Better? 🙂

sour hound
#

where do i find domain reloading

ruby python
#

oops, forgot to remove a line 😛

rich adder
slender nymph
languid spire
sour hound
#

i have no clue what domain reloading is though or if ive disabled it or not

slender nymph
#

okay so check the link i just gave you

ruby python
sour hound
#

oh i had domain reloading disabled

#

should i enable scene reloading too?

slender nymph
#

and it is perfectly fine to have domain reloading off, you just need to make sure you are properly resetting your static variables

sour hound
#

through destroying them?

rich adder
#

just cleanup like they've suggested
OnDestroy for example will run when scene is cleaning

sour hound
#

so all i have to do is shove it into my script?

rich adder
#

-= is the opposite

#

so yea

#

afaik its good practice to cleanup your subscribes regardless,
add the whole static not resetting in unity with DR off

stiff stump
#

im using OverlapBoxAll and im working if i target every layer expect one

rich adder
#

put that layer in ~mylayertoignore in the overlapbox

ruby python
#

Hmm, weird issue. Probably being an idiot.....

indicatorWater.material.SetFloat("FillLevel", playerWater/100f);

Can anyone see why this isn't adjusting the 'FillLevel' of my shader? It's exposed etc. (indicatorWater is the meshRenderer of the object)

This works fine, so it's obviously something I'm doing wrong in terms of the material grabbing.

imgWater.rectTransform.localScale = new Vector3(1, playerWater / 100, 1);
dusk minnow
#

My unity aint starting playmode why

#

it just stays in finish executing code

wintry quarry
wintry quarry
dusk minnow
ruby python
#

It's a float

dusk minnow
#

got it haha thanks mate ❤️

wintry quarry
ruby python
#

The FillLevel float on the materials Shader (shadergraph) isn't getting updated as it should.

ruby python
#

playerWater is being updated and I 'run out' and the value in the inspector doesn't change

wintry quarry
#

How are you verifying that it's being updated or not

wintry quarry
#

The material?

#

Doing indicatorWater.material creates a new material, if you aren't aware

#

specific to that particular renderer

ruby python
#

OH! Really?

wintry quarry
#

yes - use .sharedMaterial if you want the "original" material

ruby python
#

Aaaah, that would be the issue then. lol.

#

Right, gotcha, thank you 🙂

#

Hmm. Or not. Still not doing what it supposed to be doing 😕

#

This is the whole method....

public void AdjustWater(float waterUsed)
    {
        playerWater -= waterUsed;
        if (playerWater > 0) {
            //imgWater.rectTransform.localScale = new Vector3(1, playerWater / 100, 1);
            indicatorWater.sharedMaterial.SetFloat("FillLevel", playerWater/100f);
        }
        else
        {
            playerWater = 0;
            indicatorWater.sharedMaterial.SetFloat("FillLevel", 0f);
            //imgWater.rectTransform.localScale = new Vector3(0, 0, 0);
        }
    }

This lives on a singleton that I'm using as a Game Manager (not sure if that would be relevant)

#

Oh wait, I just remembered something........

#

Yep, was being an idiot. Been spending lots of time with VFX graph and forgot that with ShaderGraph you need to use the Reference and not the name. Sorry.

hollow zenith
#

Hey, what are the solutions to changing font size with in game settings?
Do you have to change font size for all gui elements separately?(that sounds wrong)

rich adder
#

whats with One Piece everywhere fr lol

modest dust
#

The one piece is real

hollow zenith
#

I had this avatar for many years, so idk

rich adder
#

some weird ass sync

hollow zenith
modest dust
#

Font size of the font asset might be what you want

amber dome
#

how to get the child's from object's?

rich adder
wintry quarry
amber dome
#

give me example?

vague furnace
wintry quarry
#

transform.GetChild(n)
foreach (Transform child in transform)
transform.Find("ChildName")

vague furnace
vague furnace
#

i have a problem where i cant display my score in the game over screen

wintry quarry
amber dome
#

ok

wintry quarry
vague furnace
#

i dont know how i have wathched many videos and read forums but i cant seem to understand it

wintry quarry
#

You need to be specific

#

what part isn't working?

#

is there an error?
Something stopping you when trying to set things up?

ivory bobcat
amber dome
crisp token
#

Assuming constant latency, shouldn't this give me the number of ticks of latency? (Tick rate = 64)

wintry quarry
#

Every component can access the Transform

vague furnace
#

i made debug and it says that it reads the playerpref but i dont know how can i attach the data from that playerpref to a text

wintry quarry
#

you have to access the Transform

#

through .transform

wintry quarry
#

You aren't trying to convert, it's a whole separate component

idle sleet
#

if you have a terrain which had width: 199 and height: 99 and you scaled it by a factor of 500 which would give you width: 99,500 and height: 49500, What would be 1 meter now be in the terrain, would it now be 500?

weary finch
#

I'm trying to profile my build and I keep getting that this is what takes the longest. What is it?

wintry quarry
weary finch
#

I see

#

Then how can I profile a shader so that I know which instructions are taking so much time? I made a custom terrain shader and is taking around 6ms to run (which doesn't make much sense since it's quite simple)

wintry quarry
#

Use the frame debugger

#

Also simple doesn't necessarily mean efficient

weary finch
weary finch
wintry quarry
#

Actually debugging or profiling a shader itself is beyond my ken. check in #archived-shaders

weary finch
#

Okay

sick glade
#

sup, i have a parent class, with two children classes (ships, and planes) All 3 share the public function UpdateTooltip()

theres some code in the base version, and then the children classes override it, but call the original within their implementation as well.

What i'd like is to be able to call the 'youngest' version of this. What I mean by this is without knowing whether it's a ship or a plane, I want to call the UpdateTooltip function with the full implementation rather than just base.

I was thinking this could have something to do with abstraction or interfaces, but I'm not that experienced with them so I thought I'd ask

hexed knot
#

I'm making a football runner for one of my Udemy courses. I want when my player collides with the "out of bounds" box collider to freeze all rigidbody constraints. I'm able to FreezeAll but i have two issues.

  1. when the FreezeAll line of code runs, the out of bounds colliders no longer stop my player.

and 2. The constraints are all checked frozen, but my player still moves.

summer stump
#

It just comes down to what the instance actually has

#

GetComponent<Vehicle(OrWhatever)>().UpdateTooltip()
Will call a plane's method if the vehicle is a plane

You can also do this with an abstract class or an interface

solemn fractal
#

hey guys that doesnt work? tu turn true and false? ```cs
void Update()
{
PlayerMovement();

    if (Input.GetMouseButtonDown(0) && canShoot){

        shouldShoot = !shouldShoot;

        Debug.Log("shoud shoot:"  + shouldShoot);
        
        if (shouldShoot){

            InvokeRepeating("Shoot", 0f, fireRate);
            
            shouldShoot = false;

        }else{

            CancelInvoke("Shoot");
        }
       
    }
       ```
crude prawn
#

then it wont invoke

solemn fractal
#
    {   
        PlayerMovement();

        if (Input.GetMouseButtonDown(1) && shouldShoot == false){

            shouldShoot = true;
            
        }else if (Input.GetMouseButtonDown(1) && shouldShoot == true){

            shouldShoot = false;
        }

        if (Input.GetMouseButtonDown(0) && canShoot && shouldShoot == true){
            
            if (shouldShoot){

                InvokeRepeating("Shoot", 0f, fireRate);
                

            }else{

                CancelInvoke("Shoot");
            }
           
        }
            
    }```
#

tryuinmg to test here

crude prawn
#

!code

eternal falconBOT
solemn fractal
#

I want basically to click one time the mouse and keep shooting

frosty hound
#

GetMouseButtonDown is already only called once. Just invoke your method there. No need for all those if bool checks.

#

Then you can cancel it on GetMouseButtonUp.

crude prawn
solemn fractal
#

but i dont want to hold the moyuse

#

i want to cliock 1 time

crude prawn
#

i think he wants to make a famas like weapon?

#

click 1 time shoot like 3 times

solemn fractal
#

like aon and off auto shoot

#

click one time, stay there shooting until i click again

crude prawn
#

you can use a bool for that

calm coral
#

Hey, what's the difference between Handles.PositionHandle() and Handles.DoPositionHandle() ?

#
public static Vector3 PositionHandle(Vector3 position, Quaternion rotation)
{
    return DoPositionHandle(position, rotation);
}
```Actually never mind, it seems the former will call the latter ![aniblobsweat](https://cdn.discordapp.com/emojis/586029851870363660.webp?size=128 "aniblobsweat")
verbal dome
#

Yeah not sure if DoPositionHandle is even supposed to be exposed lol

calm coral
verbal dome
#

Probably. The Editor API is not as clean as the game API

craggy ledge
#

hello does anyone know what this is? the character was originally at that spot for context

verbal dome
#

Maybe some component on it. Kinda looks like a wheel collider but maybe not

craggy ledge
#

the circle only shows up when i click on armature

#

when i click geometry/skeleton it disapear

crude prawn
verbal dome
#

Also it looks like you moved the child object, you probably want to move the parent instead

craggy ledge
#

but the code is in the armature, wouldn't the child also move?

verbal dome
#

Child moves with the parent, so move the parent, otherwise their positions will not match

verbal dome
#

This will result in a weird offset

#

Or is the selected object the parent?

craggy ledge
#

in edit mode, the white ring doesn't appear i think

verbal dome
#

Ah okay then. You can check the Gizmos menu and disable specific gizmos to see what is drawing it

#

Looks like it's the rig though, at least if you are using the animation rigging package

craggy ledge
#

Okay 👍 , thank you very much for the help

raven trench
#

is there something i can use instead of OnCollisionEnter so its when the object goes into the object but not necessarily collide with it

wintry quarry
#

Trigger colliders and OnTriggerEnter?

raven trench
#

ok now idk how this channel works but if i send a snippet of code could you assist me switch it from collision to trigger

#

cuz i have a thing here that i used for something else and im trying to like repurpose it cuz i have no idea how to do it from scratch

eternal falconBOT
summer stump
#

If longer than like 5 lines use a paste site

raven trench
#
private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "GameController")
        {
            this.gameObject.GetComponent<Renderer>().material.color = new Color(0, 255, 0);
        }
    }
#

this is all it is so i dont think i need a paste site

summer stump
#

So change OnCollision to OnTrigger

#

The Collision changes to Collider in the parameter

#

And collider can skip the gameObject part
collider.tag
And
collider.GetComponent

#

Also, I recommend CompareTag("GameController")
Over
.tag ==

#

That is it

raven trench
#

so collider.CompareTag you mean? or where do i put the CompareTag

summer stump
#

Oh no, one more thing,
Color takes between 0 and 1.
In this case it won't make a difference, but it will if you didn't have the max value

summer stump
raven trench
#

ok so

#
private void OnTriggerEnter(Collider collider)
    {
        if (collider.CompareTag("GameController")
        {
            this.gameObject.GetComponent<Renderer>().material.color = new Color(0, 255, 0);
        }
    }
#

should it look more like this now?

summer stump
#

Yeah, looks right.
You also need one of the colliders to be set to trigger now, of course

#

And color still has 255 instead of 1

raven trench
#

oh yeah mb mb

#

didnt read that until now

summer stump
# raven trench oh yeah mb mb

No big deal, like I said it doesn't actually matter here hahaha
It just takes it as "over the max value" and uses 1 anyway

raven trench
#

this is as easy as it is to set to trigger right

#

nothin else?

summer stump
#

Pretty small radius though. Does this thing move?

raven trench
#

yeah

#

its a vr hand lol

#

im just tryna make it so when i hit a box with my hand it doesnt actually have to collide it can go through and still activate the thing yknow

#

its not working but theres no errors so ill troubleshoot somehow

summer stump
#

OnTrigger needs a rigidbody

silk night
summer stump
#

Not sure how that works in vr

raven trench
#

yep it works now thanks lol

#

just had to add a rigidbody to the cube

#

ok i have one unrelated question now that has nothing to do with vr

#

idk why i cant figure this out for the life of me hold on

#

i have a public int called money and whenever i do this one thing it goes up by one

#

how can i call the public integer in a different script???

summer stump
#

Gotta get a reference to the object and get the script from that

#

Then just use dot notation to get the variable (or better yet, call a method)

raven trench
#

ima be real i been looking at this for like 10 minutes and i have NO idea what to do 😭 im so tired rn

summer stump
raven trench
#

ok so the object thats holding the script is the Target im trying to throw an object at, the object im trying to get it from is the box i just made green as a test, neither are instantiated

#

my goal is to on the box check if the integer is at a certain amount, then remove that amount from the integer and do something

dawn sparrow
#

Can I not pass a Vec3 into a Vec4 constructor?

#

Isn't that what this is? (from Vector4 class)

jade elk
#

how do I create multiple instances of a sprite?

crude prawn
jade elk
raven trench
#

instantiate doesnt auto delete stuff if thats what you mean

#

you have to put in a quick line after im pretty sure thats what i do

summer stump
raven trench
#

im using
[SerializeField] private Transform _target as an example
and im trying to change it to what i want so would it be
[SerializeField] private int Money;
?

summer stump
raven trench
#

the _target one?

#

the script class name of where im trying to take it from or where im trying it put it

#

i gotta go to sleep now but ill try again tommorow 🙏

summer stump
jade elk
#

how do I make it so that a sprite has a rigid body?

silk night
#

Explain what you are trying to do 😄

tough lagoon
#

You can use a Sprite in 3D, it more or less uses a plane. I think they hid it behind the
2D in package manager in 2021 or so.

But yeah, you can add a sprite. Apply a box collider. Then apply a rigidbody.

wintry quarry
#

You can use a SpriteRenderer

jade elk
wintry quarry
versed light
#

i have this attribute for my editor tool script:
[MenuItem("Tools/Asset Database")]

but its not showing in unity

wintry quarry
versed light
#

no errors

#

its on a static method

#

which the unity docs says to do

jade elk
silk night
wintry quarry
#

What are the positons of the objects?

#

Z position

versed light
# silk night Show your whole method + attribute

    //base class:
    //public abstract class DatabaseTool<T> : EditorWindow where T : Object
    public sealed class AssetDatabaseTool : DatabaseTool<TestAsset>
    {
        [MenuItem("Tools/Asset Database")]
        public static void Init()
        {
            var window = GetWindow<AssetDatabaseTool>();
            window.titleContent = new GUIContent("Asset Database");
            window.Show();
        }
    ... regular code
silk night
versed light
#

it is in editor folder

jade elk
wintry quarry
#

Not equal or behind it

#

or within its near clip plane distance

versed light
#

i edited the code to show the base class definition

#

it inherits from editor window so it should work

#

i must be misunderstanding how the attribute works

#

very confused

silk night
versed light
#

Can you make your class derived from a base generic editor window class

#

wondering if the inheritance is what's breaking it ?

wintry quarry
#

shouldn't be an issue...

#

you're triple dog sure there are no errors?

versed light
#

yeah it shouldn't but right now it should be showing a menu 😛

silk night
#
    public class PowerupDataEditor : OdinMenuEditorWindow
    {
        private string _defaultPath = "Assets/InfinityShooter/Powerup/Powerups";
        
        [MenuItem("Tools/Sidia/Powerup Data")]
        public static void OpenWindow()
        {
            GetWindow<PowerupDataEditor>().Show();
        }
[...]

this is also working for me

versed light
#

100% no errors

wintry quarry
#

show top right of console?

versed light
#

i wonder if i have two editor tools with the same menu item directory and thats broken it some how

silk night
#

oh, no gifs in here 😦

#

Have you tried turning it off and on again? 😄

versed light
wintry quarry
#

try a different path for testing sake?

jade elk
#

how do I assign a prefab?

verbal dome
#

To what?

wintry quarry
jade elk
#

I have this code right now that creates a single brick, how do I create multiple?

using UnityEngine;

[RequireComponent(typeof(BoxCollider2D))]
public class Brick : MonoBehaviour
{
    public int points = 100;
    public bool unbreakable;

    private void Start()
    {
        ResetBrick();
    }

    public void ResetBrick()
    {
        gameObject.SetActive(true);
    }
    
    private void Hit()
    {
        if (unbreakable) {
            return;
        }

        // Destroy the brick immediately
        Destroy(gameObject);

        GameManager.Instance.OnBrickHit(this);
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Ball") {
            Hit();
        }
    }
}
verbal dome
#

A field? Make a field with the [SerializeField] attribute and use the type of the component that the prefab has

wintry quarry
jade elk
#

yes

#

do I have to create a brick manager or something?

wintry quarry
#

if you want to spawn bricks in the game, you will need a script to do that, yes

#

You can certainly call it "BrickManager" if you wish. "BrickSpawner" might be more appropriate

jade elk
#

i have to create a new empty gameobject right

wintry quarry
#

for what

summer stump
wintry quarry
#

To put the script on?

#

If you want, sure

jade elk
summer stump
jade elk
#

what would this script look like?

wintry quarry
#

that's entirely up to you

summer stump
wintry quarry
#

at some point it will need to call Instantiate to spawn a brick

#

but the how, when, where, and why of spawning bricks is up to you

jade elk
#

alright

#

what does this mean?

wintry quarry
#

this means you have a broken script on some object

#

One of these, just remove it:

summer stump
# jade elk alright

The referenced script is missing 🤷‍♂️
Can happen if you rename it outside of unity or your IDE
Or with compile errors

jade elk
#

ah, got it

#
using UnityEngine;

public class BrickSpawner : MonoBehaviour
{
    public GameObject brickPrefab; // Reference to your BlackHoles prefab
    public int numberOfBricks = 5;

    void Start()
    {
        for (int i = 0; i < numberOfBricks; i++)
        {
            GameObject newBrick = Instantiate(brickPrefab, GetRandomPosition(), Quaternion.identity);
            
        }
    }

    Vector3 GetRandomPosition()
    {
        float x = Random.Range(-50f, 50f);
        float y = Random.Range(-50f, 50f);

        return new Vector3(x, y, 0f);
    }
}```
#

what do I put for the brickPrefab?

#

do I drag the sprite image of the brick to this:

#

@summer stump

summer stump
jade elk
#

yep, it works now

#

it is called BrickClone though

summer stump
#

Naming is personal. Whatever you choose is gonna be best for you (within some limits haha). But that one is fine

jade elk
#

do I delete the clone?

#

spawner code:

#

brick code

summer stump
#

I think your issue is here:

private void Hit()
{
    if (unbreakable) {
        return;
    }

    // Destroy the brick immediately
    Destroy(gameObject);

    GameManager.Instance.OnBrickHit(this);
}
#

you destroy it, THEN pass it to the gamemanager

jade elk
#

OHHHH

summer stump
#

It should last for the frame until that call 🤷‍♂️ but I dunno

jade elk
#

i first pass then destroy?

summer stump
jade elk
#

yeah that was it lol

summer stump
#

Nice

verbal dome
#

Hmm. Destroy happens at the end of the frame though 🤔

#

Oh it might actually be different because this is in the physics loop. Idk I probably have to do some testing

jade elk
#

quick question

#

nvm

summer stump
verbal dome
#

I guess we learned about another Unity quirk today

#

I use Destroy last anyway though, or just return right after it

swift crag
#

did you confirm that?

verbal dome
#

Im not on my PC until tomorrow

verbal dome
#

I would imagine that it wouldve happened to me at some point though

#

Maybe it did but my brain RAM is full

jade elk
swift crag
#

I need to see OnBrickHit.

jade elk
#
using UnityEngine;

[RequireComponent(typeof(BoxCollider2D))]
public class Brick : MonoBehaviour
{
    public int points = 100;
    public bool unbreakable;

    private void Start()
    {
        ResetBrick();
    }

    public void ResetBrick()
    {
        gameObject.SetActive(true);
    }
    
    private void Hit()
    {
        if (unbreakable) {
            return;
        }

        GameManager.Instance.OnBrickHit(this);
        
        // Destroy the brick immediately
        Destroy(gameObject);

    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.name == "Ball") {
            Hit();
        }
    }
}
swift crag
#

this is not OnBrickHit

jade elk
#
using UnityEngine;

public class BrickSpawner : MonoBehaviour
{
    public GameObject brickPrefab;
    public int numberOfBricks = 5;

    void Start()
    {
        for (int i = 0; i < numberOfBricks; i++)
        {
            GameObject newBrick = Instantiate(brickPrefab, GetRandomPosition(), Quaternion.identity);
            
        }
    }

    Vector3 GetRandomPosition()
    {
        float x = Random.Range(-5f, 5f);
        float y = Random.Range(-5f, 5f);

        return new Vector3(x, y, 0f);
    }
}```
verbal dome
#

Oh.

swift crag
#

this wouldn't cause an error even if you destroyed the game object the brick was on

jade elk
#

this is what I get right now

verbal dome
#

LoadLevel causes it to destroy in the middle of the method or what?

swift crag
#

and where does that error come from?

swift crag
#

LoadScene doesn't do anything until the next frame

slender nymph
# jade elk

click the error here and show us the stack trace

jade elk
slender nymph
#

show GameManager.Cleared

jade elk
swift crag
#

well there you go. you destroy the bricks when they're broken

#

don't do that

jade elk
#

i removed the unbreakable part

#

i think that is what caused it

verbal dome
#

I just assumed that the error came from the previous code. I shouldn't assume

swift crag
jade elk
#

so we're good now?

swift crag
#

You can access fields on a destroyed Unity object without causing an error.

slender nymph
swift crag
#

You get an error when you try to use something that Unity provides

#

like accessing gameObject

#

Don't destroy the brick. Deactivate it.

jade elk
#

so don't do this

jade elk
#

that won't work

swift crag
#

yes, because brick isn't a game object

jade elk
#

ah

swift crag
#

so you can't make it inactive

jade elk
#

i see

swift crag
#

you already know how to get the game object for the brick

jade elk
#

yep got it

verbal dome
#

I see an unconfigured VSCode

jade elk
verbal dome
#

Fortunately you can (try to) configure it or just switch to Visual Studio Community

jade elk
#

if I made a function from private to public can I access it from another class?

jade elk
#
using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class Ball : MonoBehaviour
{
    private Rigidbody2D rb;
    public float speed = 10f;

    private void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void Start()
    {
        ResetBall();
    }

    public void ResetBall()
    {
        rb.velocity = Vector2.zero;
        transform.position = Vector2.zero;

        CancelInvoke();
        Invoke(nameof(SetRandomTrajectory), 1f);
    }

    private void SetRandomTrajectory()
    {
        Vector2 force = new Vector2();
        force.x = Random.Range(-1f, 1f);
        force.y = -1f;

        rb.AddForce(force.normalized * speed, ForceMode2D.Impulse);
    }

    private void FixedUpdate()
    {
        rb.velocity = rb.velocity.normalized * speed;
    }

}
#

i want to use the random trajectory for the bricks

eternal falconBOT
swift crag
#

follow the instructions for VS Code

jade elk
#

i'll try that

swift crag
#

It can be difficult when you try to take creative liberties with the instructions

#

so, don't skip any of the steps, and read them carefully

verbal dome
#

But if you got LTS then it is probably easy

swift crag
#

The editor defaults to including the "Engineering" feature, which locks you onto an old version of the Visual Studio Editor package

#

which is fantastic.

#

i see no reason for these "features" to exist

verbal dome
#

Can you elaborate?

jade elk
#

how would I use randomTrajectory in the brick class?

swift crag
#

If one is installed, it locks the packages it uses

#

clicking "unlock" does literally nothing, which is very goofy

#

you have to remove the entire Feature (uninstalling all of its packages), then install what you want

jade elk
#

hold on, how do I attach a rigidbody to these clones?

verbal dome
#

🫠I dont think I even have that feature in my package manager. I havent't felt like upgrading in ages since my Unity is stable @swift crag

swift crag
summer stump
# swift crag these fellas

Yeah, I've learned to just say remove that package when anyone is having issues with vs code configuration, without even asking to see. It is OFTEN a culprit

swift crag
#

well, it's definitely a culprit

summer stump
verbal dome
swift crag
#

because it forbids you from installing a new enough version of the Visual Studio Editor package

wintry quarry
swift crag
#

Also, I went and tested if anything funny happens when an object is destroyed in FixedUpdate rather than Update

#

just for kicks

#

I don't see anything weird. Although, I was slightly surprised the object was destroyed at the end of the fixed update cycle

verbal dome
#

So destroyed just before Update?

swift crag
#

every log is obj == null

jade elk
swift crag
swift crag
verbal dome
#

I guess the term "frame" in the docs applies to physics frames and rendering frames accordingly

wintry quarry
swift crag
#

You might as well set up as much as you can in advance.

jade elk
swift crag
#

Show the inspector for the prefab.

verbal dome
wintry quarry
swift crag
#

you've attached it to the brick spawner

wintry quarry
#

That's the spawner

jade elk
#

the empty gameobject is my prefab

wintry quarry
#

It's not

#

That's not a prefab at all

swift crag
#

in fact, there are no prefabs in this image

jade elk
#

what?

#

how is that possible

swift crag
#

you can instnatiate any unity object

#

you're instantiating copies of the BlackHole object in your scene

jade elk
#

the brick spawner is attached to this brick prefab

wintry quarry
#

I sent you the link earlier for how to work with prefabs. I recommend you read it

jade elk
#

i did, that is how I got the spawner working

wintry quarry
#

You're spawning spawners

jade elk
#

oh

swift crag
#

you should have a spawner whose job is to create copies of a brick prefab

wintry quarry
#

Actually looks like you're spawning "Black hole"s

jade elk
#

yeah

swift crag
#

the brick prefab shouldn't exist in the scene at all

verbal dome
# swift crag

Yeah, this seems like another case of docs being wrong

swift crag
#

it's a prefab.

jade elk
#

i was too lazy to change everything from bricks to blackholes for variables

swift crag
wintry quarry
#

Anyway you seem to have skipped the whole "create a prefab and reference it" part

verbal dome
#

(Fixed)Update
Update being capitalized in the doc really adds to the confusion tbh

swift crag
jade elk
#

i added a rigid body to the black hole script, now it isn't complaining

swift crag
#

would you decide you're too lazy to put shoes on?

#

and then fall over and hurt yourself

#

that sounds really inefficient to me

jade elk
#

should I rename everything then?

swift crag
#

slow down and pay attention

swift crag
jade elk
swift crag
#

you're just referencing another object in the scene

#

there is no reason you can't do that. obviously, it works

jade elk
#

yes

swift crag
#

but what if that particular object gets destroyed?

#

it's just like any other object in your scene

#

now you can't spawn any more copies

#

a prefab is an asset

#

it doesn't exist in a specific scene

#

but you can reference it, and create copies of it

jade elk
#

hm ok

swift crag
#

it's a template

jade elk
#

so should I delete what I have right now?

swift crag
#

not quite

#

Set up the object the way you like it

#

then drag it from the hierarchy into the project window

#

bam, prefab

wintry quarry
#

Just turn it into a prefab

swift crag
#

and go read that page Praetor send again

jade elk
#

do I remove the brick prefab here?

wintry quarry
#

Don't forget to then delete the one from the scene

swift crag
#

There are no prefabs here.

#

you keep using that word

wintry quarry
#

That isn't a prefab

jade elk
#

well do I delete it then?

swift crag
#

After creating a prefab.

wintry quarry
#

There's nothing even called brick there

swift crag
#

I'm still very confused by these names, yes

#

you have a "black hole" being spawned by a brick spawner

jade elk
#

ok hold on, let me rename everything

#

since i only called it brick because the tutorial did that

swift crag
#

there are only two hard problems in computer science, and we aren't doing cache invalidation

#

naming things is the other hard problem

#

might as well not make it harder

#

I'm re-discovering how I engineered some stuff in code I wrote eight months ago

#

My names are a little bit vague and it's tripping me up

#

I have Item and InventoryItem and they're unrelated concepts

#

actually I think Item might be dead code...

#

😵‍💫

summer stump
# jade elk ok hold on, let me rename everything

Simply drag the object you want to BE a prefab into the Assets folder. It will turn blue. Then you drag the PREFAB from the assets folder into the field
Don't drag the object from the Hierarchy, because that is an actual instance of an object that can be changed and destroyed and render your reference useless

swift crag
#

in short: things in the hierarchy are real objects in your scene

#

you should reference those if you care about the specific object

#

in this case, you do not care about the specific object

#

you just want the template.

covert matrix
#

hello i need help with my code, been trying to make a gameobject inactive when the player has interacted with enough npcs, its using a debug statement as a placeholder, but it never shows up on the console for some reason

https://gdl.space/osajogecez.cpp

swift crag
#

well, who calls IncrementCompletedNPCS?

#

and do you have any proof that it's being called?

#

currently you only log if that condition is met

covert matrix
#

theres a seperate script for npcs that calls it whenver the interaction with them is done

swift crag
#

prove it by logging something at the very top of IncrementCompletedNPCS

#

maybe along with the current values of the counters

summer stump
#

I recommend this debug.
Which will also tell you if the value is being reset somehow

swift crag
#

$, not % !

covert matrix
swift crag
#

Okay, so it's not being called at all

#

Well, there is a second option

summer stump
#

Fixed

swift crag
#

You might just have the console filtered.

#

I have info and warning messages off

#

(my mouse is hovering over the info toggle, so it's kind of half-lit-up)

covert matrix
#

just to add, the counter goes up in the inspector

swift crag
#

then you definitely have the console filtered

covert matrix
#

oh yeah found it ty

jade elk
#

what does this mean

wintry quarry
# jade elk

You're trying to use a variable that doesn't exist

#

Also your IDE is not configured

jade elk
#

why wont it exist?

wintry quarry
#

Otherwise it would be underlining in red

summer stump
wintry quarry
jade elk
#

dang it

#

it was a typo

wintry quarry
jade elk
#

justt found it

summer stump
#

It can take as little as 5 minutes

ivory bobcat
swift crag
#

quit being penny wise and pound foolish. fix your code editor.

summer stump
#

Just to hammer what Dalphat said home..

swift crag
#

when I went to make that little test case earlier, I first configured my code editor

#

and that was for a throwaway project I've already deleted

jade elk
#

do I download this

#

the .net sdk

swift crag
#

Follow the instructions.

jade elk
#

i did

swift crag
#

Are you currently reading the instructions?

#

Show me what you are looking at.

jade elk
#

the unity extension was downloaded

swift crag
#

Okay, that is the correct VSCode extension to install, yes.

#

Now follow the rest of the instructions.

jade elk
#

it is installed

covert matrix
#

follow up on my question earlier, the console is showing the correct debug statements but the gameobject i want to set inactive isnt
https://gdl.space/yerefipufe.cs

summer stump
covert matrix
#

no

swift crag
#

what do you mean "isn't"?

#

it's not being deactivated?

covert matrix
#

isnt becoming deactivated*

summer stump
#

Hmm ok. You get the log, but it isn't being deactivated it.
Do you set it active anywhere else?

covert matrix
#

it becomes active when an npc interaction ends, but i dont think it continously keeps it active?

jade elk
#

how do I know the extension was installed correctly?

#

@swift crag

#

i see these now?

swift crag
#

Errors should now be highlighted, and names should be getting auto-completed

summer stump
#

then log wherever you activate it?

#

Not sure

#

Or just put breakpoints

jade elk
#

why can't i assign this:

blackholes = FindObjectOfType<Blackhole>();

to this:

private Blackhole[] blackholes;
#

it worked when the variables were called brick

summer stump
#

There is FindObjectsOfType though

#

(note the s)

covert matrix
jade elk
#

finally got the renaming of variables done

#

ah so i do have a prefabs folder

covert matrix
#

the overworld canvas is currently active, once i interact with 4 npcs, the overworld canvas should become inactive but its not
the placeholder becomes active though

https://gdl.space/edutucogun.cs

jade elk
#

how would you guys loop through the game objects in the array?

gaunt ice
#

Google c# loop

jade elk
summer stump
jade elk
#

im trying to plan how to implement a gravitational force between every black hole

#

yeah

summer stump
#

a loop inside a loop

jade elk
#

i think i have to apply the Fg = (G * m1 * m2) / r^2 formula between every game object

#

right?

gaunt ice
#

Then this is not loop, it is backtracking, basically:
Void dfs(int idx){
If idx>=length return
take this, dfs(idx+1)
Skip this, dfs(idx+1)
}

#

Typing in phone is painful

jade elk
#

ill try that, do you think i should make a class called force calculator?

#

or just do it in a function

#

im not sure how to plan this

gaunt ice
#

An algorithm has nothing to do with class

#

But making a struck will make your life easier since you can load the data you need as struct properties no need to pass it in next function call to dfs

#

private struct solution{
Properties
Constructor()//or driver
Run()//returns the result
Other helper methods
}

lean basin
#

hello, why do unity and visual studio said this project had compiler error even though the script existed?
BuildManager doesn't exist it said. But it exist in the file.

There are no compiler error in my coworkers' PC, but only here. Why?

gaunt ice
#

Try reimport it

versed light
#

trying to add a mesh to my asset as a subasset in the asset database but i get the error:
Couldn't add object to asset file because the Mesh is already an asset doesn't really make sense because its just a mesh instance but not saved to the asset database am i missing something to get tihs to work

silver dock
#

hello, once again i need help with my event script
https://hatebin.com/qujocbmhah
Can someone look at it and tell me how i can make the events occur at random years, currently they just occur as soon as they can, and they completely ignore their odds even if it is set to 0.0001 they occur as soon as possible one after one

versed light
#

wtf my script is automatically saving meshes to my scriptable object 🤔

#

so confused

gaunt ice
#

Where you check the probability

#

In trigger event

silver dock
gaunt ice
#

I am on my phone and i maybe overlook the code, but i cant see some codes like: if some random value>odd then active event in trigger event

summer stump
opal fossil
#

do i use a character controller or rigidbody if im controlling a ragdoll

oblique ginkgo
#

For physics based stuff you use rigidbodies

opal fossil
#

alright

eternal needle
opal fossil
eternal needle
#

Im not sure what you mean in your last sentence tbh

opal fossil
#

i tried using a rigidbody at the root gameobject but it starts behaving weirdly.

#

the character ignores other colliders and just phazes through like it's a trigger

eternal needle
#

This isnt 1 rigidbody you would need, you need like 10+. One for each body part.
Typically I saw people use the hips of the ragdoll to move it, as that's the center of mass. So you would apply any velocity changes to that rb. If you're object is going through other colliders then you're likely not moving in a way which respects physics even

#

Making an active ragdoll as a player is honestly very hard, I'd recommend experimenting more with unity before doing this.

opal fossil
opal fossil
eternal needle
#

Itll just be a lot of experimenting to fine tune values like how much force the limbs should apply to reach their desired rotation. Then you'll probably add more like grabbing and other physics based interactions. It is a lot in comparison to a normal character

#

If you just want something that ragdolls on death then it's a lot simpler. You just toggle all the rigidbodies/colliders for the ragdoll, without worrying about it needing to stand

opal fossil
solemn fractal
#

Hey guys, instead of doing like that to invoke the boss the times I want, is there a better way to do this?

gaunt ice
#

Why the invokebossone is invoked in 240 and 20 seconds later it is invoked again
Btw use coroutine or timer

solemn fractal
cunning elbow
#

Hi guys. I just learned about the singleton pattern. What are the most common design patterns when developing games ? Are there any patterns that i have to know about other than the singleton

teal viper
#

State machines, events, dependency injection. Stuff like that.

#

Maybe SOLID principles

keen dew
teal viper
#

What's neat.

burnt vapor
#

Have fun

gaunt ice
#

spawnerTime should not be increased, just assignment

burnt vapor
#

I don't know what you're talking about

gaunt ice
#

+= to =, otherwise the spawner time just keep increasing

burnt vapor
#

Indeed, so the code is correct

#

This code changes the spawnerTime to 140, then 160, then 220, then 280

#

The only mistake I made here is that the initial question actually changes from 120 to 240, so the first increase should have an extra 100

#

But this code should not be taken too literally to begin with

hexed terrace
#

They're only those values in the original code because they're all invoked at the same time. In a coroutine you don't need the timer to increase in the same way, just be the correct value for between each spawn

burnt vapor
#

Oooh, you're correct, they should be assigned rather than incremented. My mistake

gray flower
#

If i have an animator and ive replaced it with an animator controller override. And i wanna do animator.Play(clip); what do i put in there? The overwriter clip name or the original clip name?

queen adder
#

Just need some help with some (basic?) maths.

So on my character controller the rotation of my Camera and Player are different but I want the rotation of my player to depend on movement keys + camera rotation.

character.forward = Vector3.Slerp(character.forward, moveDir, Time.deltaTime * rotateSpeed);```So how can I adjust this to take into account my camera rotation? I assume I multiple moveDir by some normalised value of camera rotation?

moveDir is just a vector2 of (X, Z)
#

Or maybe some use of the camera.forward? Dunkthink

queen adder
#

If I multiply moveDir using the camera, it only works when moving diagonally

#

So if I hold "W" and "D" the character faces the same direction of the camera regardless of direction but if I hold 1 direction by itself it changes nothing and just always uses world position

#

Ahh I'm stupid... I need to use the camera.right for the "x" that's why it only works with 1?

#

🙂 Sorted

tawdry mirage
#

if i do this.variable = variable; are there noob traps?

#

instead of something like variable = _variable

languid spire
tawdry mirage
# languid spire no that's fine

ok, thank you. In every tutorial a watched no one did this, they all did either variable = _variable or variable = variableNew

winged thistle
fast oracle
#

Can someone explain what this highlighted code does?

wintry quarry
#

It declares a list variable, creates a list object, and assigns the variable to refer to that object

fast oracle
#

the assigning is to ContactPoint2D right

wintry quarry
#

No? It's to a list that can hold ContactPoint2Ds

fast oracle
#

what is it referring to?

#

"ssigns the variable to refer to that object"

#

what object?

wintry quarry
#

The list

fast oracle
#

is it a list that already exists?

#

or is it just a list that holds a value or type ContactPoints2D

wintry quarry
#

No, the list is created by new()

#

It is a list that can only hold ContactPoint2Ds

#

It's the same as new List<ContactPoint2D>()

fast oracle
#

II see

oblique gale
#

how do I make it so that it will automatically play the fade out after fade in? when I triggered the fade in in the code it won't play the fade out

silk night
burnt vapor
tawdry mirage
burnt vapor
#

You're confusing it with having both a public getter and a setter

#

There's also init; but this is not supported in Unity I believe. The use case is quite niche, though

tawdry mirage
sharp abyss
#

is there a way to start a coroutine from another script? I tried this gameObject.TryGetComponent<pickupweapon>(out pickupweapon PickupScript); StartCoroutine(PickupScript.ChangeValues()); but got this error 'pickupweapon.ChangeValues()' is inaccessible due to its protection level

fast oracle
#

is it public?

sharp abyss
teal viper
sharp abyss
#

I didnt know that we can put public or private before IEnumerator

teal viper
#

IEnumerator is just a return type of the method.

wintry quarry
#

best practice is for a script to run all of its own coroutines

#

e.g. instead of doing StartCoroutine(PickupScript.ChangeValues());, you should do PickupScript.BeginChangingValues(); where BeginChangingValues is a function that starts the ChangeValues script internally from that script

#

e.g.

public void BeginChangingValues() {
  StartCoroutine(ChangeValues());
}```
#

this ensures that the ChangeValues coroutine's life cycle is tied to the script that owns it, rather than some other random script/object

mild mortar
rich adder
#

child don't move parents

mild mortar
#

Ah okay

#

Gotcha

#

Thanks

queen yoke
#

please advice couse for c# unity

normal arrow
#

Hi guys ! I want to use an AddListenerEvent on my toggle but only if the toggle became True and not on true to false. I did something like that but it didnt work :
myToggle.onValueChanged.AddListener((on) => {MyFunction();});

wintry quarry
runic lotus
#

Hey! anyone here worked with microsoft's mesh toolkit before ?

wintry quarry
#
myToggle.onValueChanged.AddListener((on) => {
  if (on) {
    MyFunction();
  }
});``` @normal arrow
normal arrow
#

Thank's man ! didn't know i could do it like that ! it works perfectly

rich adder
queen yoke
#

plz advice udemy couse

mild mortar
#

I've made some cylinders and squashed them down a bit to be rotating circular floors, so their scale isn't 1 currently.

I know that there is a typical thing people do of parenting the player to the platform so that the character moves with it. But doesn't it usually introduce a bug of the character model etc stretching and bugging out if the scale isn't 1?

Not sure how I can make this work and avoid that problem

wintry quarry
summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

queen yoke
summer stump
final kestrel
#

https://hatebin.com/zzpqekrtar Hello! sorry if its too obvious but I cannot seem to wrap my head around why my game starts paused and I cannot unpause it.

summer stump
#

In fixedupdate
If not paused, pause

#

Then else
Unpause

Then the next cycle it's not paused, so it pauses

wintry quarry
queen yoke
#

i can't find video playlist start from begin

swift crag
#

unity learn articles have videos embedded in them.

final kestrel
#

What I had in mind that I shouldnt read the input in fixed update so thats why i set them in update

#

and im basically trying to execute them on fixed update

wintry quarry
final kestrel
#

The game does not stop on update

wintry quarry
#

but I think you're confused about the difference between the else block on GetKeyDown and another GetKeyDown

final kestrel
final kestrel
summer stump
wintry quarry
#

the fact that you have an else on the GetKeyDown in Update is almost definitely not what you want

final kestrel
#

I used an else if

wintry quarry
#

pointlessly

final kestrel
#

ahh okay

#

Oh okay it works now

#

But my ui scripts that are on the text do not work

#

also when I press retry the game still starts paused. What is the problem?

wintry quarry
#

idk what your current code looks like

#

I assume you still have the FixedUpdate thing happening

final kestrel
#

Ah no I removed it from fixed update as you said

#

I'll send the code in a min i gotta eat.

#

what i think is I probably reset the time scale to 1 when I press retry so it does not start paused

wintry quarry
#

because timeScale is not going to reset when reloading the scene

obsidian parcel
#

hi i am getting massive fps drop like from 800 to 200 if i use spline and animate something on it do anyone knows the reason in editor?

#

using spline animate

wintry quarry
final kestrel
wintry quarry
#

if your script depends on time scale, probably yes

final kestrel
#

All right I will do as you say after dinner. Thanks a lot.

#

Its got coroutines

wintry quarry
#

if they're using WaitForSeconds or Time.deltaTime, then yes

#

you can use WaitForSecondsRealtime or Time.unscaledDeltaTime to fix

final kestrel
#

Ahh so helpful thanks a lot. I will look into it.

rich bluff
#

800 fps is 0.00125 ms per frame, 200 is 0.005 ms

#

difference of fractions of ms

#

understand that massive over 200 fps numbers are only possible with absolutely minimal load

#

the more load you put the less and less the difference will be

#

in fps

#

you need to set yourself some target ms per frame budget, like 60 fps is 0.0166 seconds or 16 ms

obsidian parcel
#

like fixed frames to test?

rich bluff
#

no, its not fixed its just an arbitrary budget you set for the project

obsidian parcel
#

but will also not depends on graphic card or cpu

rich bluff
#

console games that run at 30 aim at 32 ms per frame

#

yes ofc, that is up to you to design for min/recommended/max specs

#

and ensure that the game can run at decent framerates on the hw you said it would

obsidian parcel
#

cause rightnow im testing this thing on 4070 but if i go down that 200 will also go down to a lot

#

not sure why this drop like im just animating one cube on spline

rich bluff
#

what causes the drop some spline animation?

#

add 10 more

obsidian parcel
#

i added 50 more the fps remains same

#

200

rich bluff
#

then its all good

#

800 fps is indicator of nothing is happening at all

obsidian parcel
#

but sometimes some cubes donot move it just stays their

summer stump
obsidian parcel
#

not sure how to see the profiler that much but massively i see the other section too much

summer stump
#

Not sure what you mean by "that much"

You just open the profiler and see what is taking the most time

obsidian parcel
#

like i use the profiler like 2-3 times

summer stump
#

Then dig down to what takes the most time

rich bluff
#

click to switch to hierarchy its easier to parse